From 1aaf7dee3b9f6502ed93554fdec642c1c8e8ebe4 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 10 Mar 2022 09:47:22 +0100 Subject: [PATCH 1/2] Prepare issue branch. --- pom.xml | 2 +- spring-data-mongodb-benchmarks/pom.xml | 2 +- spring-data-mongodb-distribution/pom.xml | 2 +- spring-data-mongodb/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0e9257f0f0..2cc94d543f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 3.4.0-SNAPSHOT + 3.4.0-GH-3984-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml index e2704a6753..d19806f0ed 100644 --- a/spring-data-mongodb-benchmarks/pom.xml +++ b/spring-data-mongodb-benchmarks/pom.xml @@ -7,7 +7,7 @@ org.springframework.data spring-data-mongodb-parent - 3.4.0-SNAPSHOT + 3.4.0-GH-3984-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index b75f8bf624..434715b343 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-mongodb-parent - 3.4.0-SNAPSHOT + 3.4.0-GH-3984-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index ca96626cc9..c0937959e9 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -11,7 +11,7 @@ org.springframework.data spring-data-mongodb-parent - 3.4.0-SNAPSHOT + 3.4.0-GH-3984-SNAPSHOT ../pom.xml From 2f91f42adbb9c9e3356e43a8b64e609839f04b20 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 10 Mar 2022 14:30:08 +0100 Subject: [PATCH 2/2] 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. --- .../data/mongodb/core/MongoTemplate.java | 2 +- .../data/mongodb/core/MongoTemplateUnitTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java index 3d159c6e9e..bc12ed18ae 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java @@ -634,7 +634,7 @@ public MongoCollection createCollection(String collectionName, @Nullable CollectionOptions collectionOptions) { Assert.notNull(collectionName, "CollectionName must not be null!"); - return doCreateCollection(collectionName, convertToDocument(collectionOptions)); + return doCreateCollection(collectionName, convertToDocument(collectionOptions, Object.class)); } /* diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java index f5953d0384..57ace74d33 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateUnitTests.java @@ -2289,6 +2289,18 @@ void createCollectionShouldSetUpTimeSeries() { .granularity(TimeSeriesGranularity.HOURS).toString()); } + @Test // GH-3984 + void templatePassesOnTimeSeriesOptionsWhenNoTypeGiven() { + + template.createCollection("time-series-collection", CollectionOptions.timeSeries("time_stamp")); + + ArgumentCaptor options = ArgumentCaptor.forClass(CreateCollectionOptions.class); + verify(db).createCollection(any(), options.capture()); + + assertThat(options.getValue().getTimeSeriesOptions().toString()) + .isEqualTo(new com.mongodb.client.model.TimeSeriesOptions("time_stamp").toString()); + } + class AutogenerateableId { @Id BigInteger id;