Open salvatorenovelli opened 1 month ago
Thank our for the report. Sounds like we should update the documentation stressing that enabling auto index creation (disabled by default) can interfere with manual collection creation.
Fair enough as a position but auto-index creation is a very neat feature. It's not just about creating indexes in a new database, it's also about failing fast, with meaningful exceptions if indexes are created in the wrong way in an existing database. Auto-index creation allows for a reliable database configuration but also run-time assertions based on annotations specified on a single place.
Another option you could consider, if valuable to enough users, could be to provide an option to disable auto-index creation specifically for time-series collections.
Hi there, according to Index and Collection Management document page, timeseries collection should be created before inserting data to make sure they're created as a
type
= "timeseries". (instead of a plain "collection")As mentioned in the documentation, there are 2 ways to do this:
MongoTemplate
in conjunction withCreateCollectionOptions
.MongoTemplate
pulling the option from the@TimeSeries
annotation.Option 1 works, but only if no
@TimeSeries
annotation is present on the class, but Option 2 does not seem to work at all. Whenever a@TimeSeries
annotation is present on the class, any attempt to configure it will fail with an "Collection already exist exception". This seems to be related to the fact that collections are automatically created byMongoPersistentEntityIndexCreator
to ensure indexes are created, but this creator seems to ignore the fact the the collection is a TimeSeries and creates it as a plain "collection".The work-around is quite simple, removing the annotation gives you a chance to create it imperatively, but it doesn't feel the most consistent way given all my other collections are correctly created and configured via annotations.
For reference, in Option 2 I use the code provided in the documentation: