I’m using Spring Data MongoDB to interact with a MongoDB database. In my application, I have a Test
class annotated as a time series collection using the @TimeSeries
annotation as follows:
TimeSeries(
timeField = "timestamp",
granularity = Granularity.SECONDS,
metaField = "deviceId")
public class Test {
@Id private String id;
private String deviceId;
private OffsetDateTime timestamp;
private int measurement;
.....
}
When I explicitly use the mongoTemplate.createCollection(Test.class)
method, the collection is created as a time series collection as expected. However, if I directly insert data without pre-creation like:
List<Test> testObjectsList = //list of Test objects;
mongoTemplate.insertAll(testObjectsList);
It results in a standard collection, despite having the class annotated with @TimeSeries
.
Why does this happen? Why doesn’t MongoDB recognize the @TimeSeries
annotation during direct insertion?