Skip to content

Commit 2bb8643

Browse files
christophstroblmp911de
authored andcommitted
Propagate time series options correctly.
This commit fixes an issue when creating a collection via MongoTemplate without passing on type information. In this case potential time series information was lost. Closes #3984 Original pull request: #3990.
1 parent 8de07fc commit 2bb8643

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ public MongoCollection<Document> createCollection(String collectionName,
676676
@Nullable CollectionOptions collectionOptions) {
677677

678678
Assert.notNull(collectionName, "CollectionName must not be null!");
679-
return doCreateCollection(collectionName, convertToDocument(collectionOptions));
679+
return doCreateCollection(collectionName, convertToDocument(collectionOptions, Object.class));
680680
}
681681

682682
/*

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java

+12
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,18 @@ void stillUsesCountDocumentsForNonEmptyQueryEvenIfEstimationEnabled() {
23172317
verify(collection).countDocuments(any(Document.class), any());
23182318
}
23192319

2320+
@Test // GH-3984
2321+
void templatePassesOnTimeSeriesOptionsWhenNoTypeGiven() {
2322+
2323+
template.createCollection("time-series-collection", CollectionOptions.timeSeries("time_stamp"));
2324+
2325+
ArgumentCaptor<CreateCollectionOptions> options = ArgumentCaptor.forClass(CreateCollectionOptions.class);
2326+
verify(db).createCollection(any(), options.capture());
2327+
2328+
assertThat(options.getValue().getTimeSeriesOptions().toString())
2329+
.isEqualTo(new com.mongodb.client.model.TimeSeriesOptions("time_stamp").toString());
2330+
}
2331+
23202332
class AutogenerateableId {
23212333

23222334
@Id BigInteger id;

0 commit comments

Comments
 (0)