Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@TimeSeries collection is ceated as a "collection" type on startup #4792

Open
salvatorenovelli opened this issue Sep 23, 2024 · 2 comments
Open
Assignees
Labels
type: documentation A documentation update

Comments

@salvatorenovelli
Copy link

salvatorenovelli commented Sep 23, 2024

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:

  1. Using MongoTemplate in conjunction with CreateCollectionOptions.
  2. Using 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 by MongoPersistentEntityIndexCreator 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:

@TimeSeries(collection="weather", timeField = "timestamp")
public class Measurement {
    String id;
    Instant timestamp;
    // ...
}

template.createCollection(Measurement.class);
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 23, 2024
@christophstrobl
Copy link
Member

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.

@christophstrobl christophstrobl self-assigned this Sep 26, 2024
@christophstrobl christophstrobl added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 26, 2024
@salvatorenovelli
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants