Allow creating time series collections with custom name and CollectionOptions derived from annotation #4684
Labels
status: feedback-provided
Feedback has been provided
status: waiting-for-triage
An issue we've not yet triaged
According to the documentation, it is possible to create a time series collection via
MongoTemplate
by either providing explicitCollectionOptions
or a class annotated with@TimeSeries
:in which case the
CollectionOptions
are derived from the annotation:spring-data-mongodb/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java
Lines 1058 to 1081 in b8b93bc
However, if you want to create the collection with a custom name (not derived from the class), there is currently no option for deriving the
CollectionOptions
from the annotation. The only overloads ofmongoTemplate.createCollection
that take aString collectionName
also require explicitCollectionOptions
.Using
mongoTemplate.save(value, "myCustomName")
is a non-starter since it does not read the entity metadata and just creates a basic collection (not a time series) with no other options.Custom names are important for several widespread use cases, for example collection-level multi-tenancy, where you would create multiple collection with the same definition to segregate data for different tenants, or any other types of data segmentation.
I propose new methods to create a collection that take both the collectionName and the entityClass as inputs:
The text was updated successfully, but these errors were encountered: