Skip to content

Commit 5dbdaca

Browse files
Remove MongoDB driver 4 compatibility.
Closes: #4886
1 parent daf6827 commit 5dbdaca

18 files changed

+15
-602
lines changed

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

-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import java.util.concurrent.TimeUnit;
1919

2020
import org.bson.Document;
21-
2221
import org.springframework.core.convert.converter.Converter;
2322
import org.springframework.data.mongodb.core.index.IndexDefinition;
2423
import org.springframework.data.mongodb.core.index.IndexInfo;
25-
import org.springframework.data.mongodb.util.MongoCompatibilityAdapter;
2624
import org.springframework.lang.Nullable;
2725
import org.springframework.util.ObjectUtils;
2826

@@ -90,9 +88,6 @@ private static Converter<IndexDefinition, IndexOptions> getIndexDefinitionIndexO
9088
if (indexOptions.containsKey("bits")) {
9189
ops = ops.bits((Integer) indexOptions.get("bits"));
9290
}
93-
if (indexOptions.containsKey("bucketSize")) {
94-
MongoCompatibilityAdapter.indexOptionsAdapter(ops).setBucketSize(((Number) indexOptions.get("bucketSize")).doubleValue());
95-
}
9691
if (indexOptions.containsKey("default_language")) {
9792
ops = ops.defaultLanguage(indexOptions.get("default_language").toString());
9893
}

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

-18
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
import org.bson.UuidRepresentation;
2727
import org.bson.codecs.configuration.CodecRegistry;
28-
2928
import org.springframework.beans.factory.config.AbstractFactoryBean;
30-
import org.springframework.data.mongodb.util.MongoCompatibilityAdapter;
3129
import org.springframework.lang.Nullable;
3230
import org.springframework.util.CollectionUtils;
3331
import org.springframework.util.StringUtils;
@@ -57,8 +55,6 @@ public class MongoClientSettingsFactoryBean extends AbstractFactoryBean<MongoCli
5755

5856
private CodecRegistry codecRegistry = DEFAULT_MONGO_SETTINGS.getCodecRegistry();
5957

60-
@Nullable private Object streamFactoryFactory = MongoCompatibilityAdapter
61-
.clientSettingsAdapter(DEFAULT_MONGO_SETTINGS).getStreamFactoryFactory();
6258
@Nullable private TransportSettings transportSettings;
6359

6460
private ReadPreference readPreference = DEFAULT_MONGO_SETTINGS.getReadPreference();
@@ -371,16 +367,6 @@ public void setReadPreference(ReadPreference readPreference) {
371367
this.readPreference = readPreference;
372368
}
373369

374-
/**
375-
* @param streamFactoryFactory
376-
* @deprecated since 4.3, will be removed in the MongoDB 5.0 driver in favor of
377-
* {@code com.mongodb.connection.TransportSettings}.
378-
*/
379-
@Deprecated(since = "4.3")
380-
public void setStreamFactoryFactory(Object streamFactoryFactory) {
381-
this.streamFactoryFactory = streamFactoryFactory;
382-
}
383-
384370
public void setTransportSettings(@Nullable TransportSettings transportSettings) {
385371
this.transportSettings = transportSettings;
386372
}
@@ -492,10 +478,6 @@ protected MongoClientSettings createInstance() {
492478
builder.transportSettings(transportSettings);
493479
}
494480

495-
if (streamFactoryFactory != null) {
496-
MongoCompatibilityAdapter.clientSettingsBuilderAdapter(builder).setStreamFactoryFactory(streamFactoryFactory);
497-
}
498-
499481
if (retryReads != null) {
500482
builder = builder.retryReads(retryReads);
501483
}

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
import org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter;
108108
import org.springframework.data.mongodb.core.timeseries.Granularity;
109109
import org.springframework.data.mongodb.core.validation.Validator;
110-
import org.springframework.data.mongodb.util.MongoCompatibilityAdapter;
111110
import org.springframework.data.projection.EntityProjection;
112111
import org.springframework.data.util.CloseableIterator;
113112
import org.springframework.data.util.Optionals;
@@ -728,7 +727,7 @@ public boolean collectionExists(String collectionName) {
728727

729728
return execute(db -> {
730729

731-
for (String name : MongoCompatibilityAdapter.mongoDatabaseAdapter().forDb(db).listCollectionNames()) {
730+
for (String name : db.listCollectionNames()) {
732731
if (name.equals(collectionName)) {
733732
return true;
734733
}
@@ -1977,11 +1976,6 @@ public <T> List<T> mapReduce(Query query, Class<?> domainType, String inputColle
19771976
mapReduce = mapReduce.jsMode(mapReduceOptions.getJavaScriptMode());
19781977
}
19791978

1980-
if (mapReduceOptions.getOutputSharded().isPresent()) {
1981-
MongoCompatibilityAdapter.mapReduceIterableAdapter(mapReduce)
1982-
.sharded(mapReduceOptions.getOutputSharded().get());
1983-
}
1984-
19851979
if (StringUtils.hasText(mapReduceOptions.getOutputCollection()) && !mapReduceOptions.usesInlineOutput()) {
19861980

19871981
mapReduce = mapReduce.collectionName(mapReduceOptions.getOutputCollection())
@@ -2364,7 +2358,7 @@ protected String replaceWithResourceIfNecessary(String function) {
23642358
public Set<String> getCollectionNames() {
23652359
return execute(db -> {
23662360
Set<String> result = new LinkedHashSet<>();
2367-
for (String name : MongoCompatibilityAdapter.mongoDatabaseAdapter().forDb(db).listCollectionNames()) {
2361+
for (String name : db.listCollectionNames()) {
23682362
result.add(name);
23692363
}
23702364
return result;

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
import org.springframework.data.mongodb.core.query.Query;
119119
import org.springframework.data.mongodb.core.query.UpdateDefinition;
120120
import org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter;
121-
import org.springframework.data.mongodb.util.MongoCompatibilityAdapter;
122121
import org.springframework.data.projection.EntityProjection;
123122
import org.springframework.data.util.Optionals;
124123
import org.springframework.lang.Nullable;
@@ -739,7 +738,7 @@ public <T> Mono<Boolean> collectionExists(Class<T> entityClass) {
739738

740739
@Override
741740
public Mono<Boolean> collectionExists(String collectionName) {
742-
return createMono(db -> Flux.from(MongoCompatibilityAdapter.reactiveMongoDatabaseAdapter().forDb(db).listCollectionNames()) //
741+
return createMono(db -> Flux.from(db.listCollectionNames()) //
743742
.filter(s -> s.equals(collectionName)) //
744743
.map(s -> true) //
745744
.single(false));
@@ -787,7 +786,7 @@ public ReactiveBulkOperations bulkOps(BulkMode mode, @Nullable Class<?> entityTy
787786

788787
@Override
789788
public Flux<String> getCollectionNames() {
790-
return createFlux(db -> MongoCompatibilityAdapter.reactiveMongoDatabaseAdapter().forDb(db).listCollectionNames());
789+
return createFlux(db -> db.listCollectionNames());
791790
}
792791

793792
public Mono<MongoDatabase> getMongoDatabase() {
@@ -2171,10 +2170,6 @@ public <T> Flux<T> mapReduce(Query filterQuery, Class<?> domainType, String inpu
21712170
publisher = publisher.jsMode(options.getJavaScriptMode());
21722171
}
21732172

2174-
if (options.getOutputSharded().isPresent()) {
2175-
MongoCompatibilityAdapter.mapReducePublisherAdapter(publisher).sharded(options.getOutputSharded().get());
2176-
}
2177-
21782173
if (StringUtils.hasText(options.getOutputCollection()) && !options.usesInlineOutput()) {
21792174
publisher = publisher.collectionName(options.getOutputCollection()).action(options.getMapReduceAction());
21802175

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.mongodb.core.encryption;
1717

18-
import static org.springframework.data.mongodb.util.MongoCompatibilityAdapter.rangeOptionsAdapter;
19-
2018
import java.util.Map;
2119
import java.util.function.Supplier;
2220

@@ -124,7 +122,7 @@ protected RangeOptions rangeOptions(Map<String, Object> attributes) {
124122
Assert.isInstanceOf(Integer.class, trimFactor, () -> String
125123
.format("Expected to find a %s but it turned out to be %s.", Integer.class, trimFactor.getClass()));
126124

127-
rangeOptionsAdapter(encryptionRangeOptions).trimFactor((Integer) trimFactor);
125+
encryptionRangeOptions.trimFactor((Integer) trimFactor);
128126
}
129127

130128
if (attributes.containsKey("sparsity")) {

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

-10
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@
114114
*/
115115
GeoSpatialIndexType type() default GeoSpatialIndexType.GEO_2D;
116116

117-
/**
118-
* The bucket size for {@link GeoSpatialIndexType#GEO_HAYSTACK} indexes, in coordinate units.
119-
*
120-
* @since 1.4
121-
* @return {@literal 1.0} by default.
122-
* @deprecated since MongoDB server version 4.4
123-
*/
124-
@Deprecated
125-
double bucketSize() default 1.0;
126-
127117
/**
128118
* The name of the additional field to use for {@link GeoSpatialIndexType#GEO_HAYSTACK} indexes
129119
*

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

-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.bson.Document;
2121
import org.springframework.data.mongodb.core.query.Collation;
22-
import org.springframework.data.mongodb.util.MongoClientVersion;
2322
import org.springframework.lang.Nullable;
2423
import org.springframework.util.Assert;
2524
import org.springframework.util.StringUtils;
@@ -41,7 +40,6 @@ public class GeospatialIndex implements IndexDefinition {
4140
private @Nullable Integer max;
4241
private @Nullable Integer bits;
4342
private GeoSpatialIndexType type = GeoSpatialIndexType.GEO_2D;
44-
private Double bucketSize = MongoClientVersion.isVersion5orNewer() ? null : 1.0;
4543
private @Nullable String additionalField;
4644
private Optional<IndexFilter> filter = Optional.empty();
4745
private Optional<Collation> collation = Optional.empty();
@@ -107,17 +105,6 @@ public GeospatialIndex typed(GeoSpatialIndexType type) {
107105
return this;
108106
}
109107

110-
/**
111-
* @param bucketSize
112-
* @return this.
113-
* @deprecated since MongoDB server version 4.4
114-
*/
115-
@Deprecated
116-
public GeospatialIndex withBucketSize(double bucketSize) {
117-
this.bucketSize = bucketSize;
118-
return this;
119-
}
120-
121108
/**
122109
* @param fieldName
123110
* @return this.
@@ -203,14 +190,9 @@ public Document getIndexOptions() {
203190
break;
204191

205192
case GEO_2DSPHERE:
206-
207193
break;
208194

209195
case GEO_HAYSTACK:
210-
211-
if (bucketSize != null) {
212-
document.put("bucketSize", bucketSize);
213-
}
214196
break;
215197
}
216198

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

-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Iterator;
2626
import java.util.List;
2727
import java.util.Map;
28-
import java.util.Optional;
2928
import java.util.Set;
3029
import java.util.concurrent.TimeUnit;
3130
import java.util.function.Supplier;
@@ -55,7 +54,6 @@
5554
import org.springframework.data.mongodb.util.BsonUtils;
5655
import org.springframework.data.mongodb.util.DotPath;
5756
import org.springframework.data.mongodb.util.DurationUtil;
58-
import org.springframework.data.mongodb.util.MongoClientVersion;
5957
import org.springframework.data.mongodb.util.spel.ExpressionUtils;
6058
import org.springframework.data.spel.EvaluationContextProvider;
6159
import org.springframework.data.util.TypeInformation;
@@ -711,23 +709,6 @@ protected IndexDefinitionHolder createGeoSpatialIndexDefinition(String dotPath,
711709
.named(pathAwareIndexName(index.name(), dotPath, persistentProperty.getOwner(), persistentProperty));
712710
}
713711

714-
if (MongoClientVersion.isVersion5orNewer()) {
715-
716-
Optional<Double> defaultBucketSize = MergedAnnotation.of(GeoSpatialIndexed.class).getDefaultValue("bucketSize",
717-
Double.class);
718-
if (!defaultBucketSize.isPresent() || index.bucketSize() != defaultBucketSize.get()) {
719-
indexDefinition.withBucketSize(index.bucketSize());
720-
} else {
721-
if (LOGGER.isInfoEnabled()) {
722-
LOGGER.info(
723-
"GeoSpatialIndexed.bucketSize no longer supported by Mongo Client 5 or newer. Ignoring bucketSize for path %s."
724-
.formatted(dotPath));
725-
}
726-
}
727-
} else {
728-
indexDefinition.withBucketSize(index.bucketSize());
729-
}
730-
731712
indexDefinition.typed(index.type()).withAdditionalField(index.additionalField());
732713

733714
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);

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

-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class MapReduceOptions {
4545
private Boolean verbose = Boolean.TRUE;
4646
private @Nullable Integer limit;
4747

48-
private Optional<Boolean> outputSharded = Optional.empty();
4948
private Optional<String> finalizeFunction = Optional.empty();
5049
private Optional<Collation> collation = Optional.empty();
5150

@@ -152,19 +151,6 @@ public MapReduceOptions actionReplace() {
152151
return this;
153152
}
154153

155-
/**
156-
* If true and combined with an output mode that writes to a collection, the output collection will be sharded using
157-
* the _id field. For MongoDB 1.9+
158-
*
159-
* @param outputShared if true, output will be sharded based on _id key.
160-
* @return MapReduceOptions so that methods can be chained in a fluent API style
161-
*/
162-
public MapReduceOptions outputSharded(boolean outputShared) {
163-
164-
this.outputSharded = Optional.of(outputShared);
165-
return this;
166-
}
167-
168154
/**
169155
* Sets the finalize function
170156
*
@@ -245,10 +231,6 @@ public Optional<String> getOutputDatabase() {
245231
return this.outputDatabase;
246232
}
247233

248-
public Optional<Boolean> getOutputSharded() {
249-
return this.outputSharded;
250-
}
251-
252234
public Map<String, Object> getScopeVariables() {
253235
return this.scopeVariables;
254236
}
@@ -336,7 +318,6 @@ protected Document createOutObject() {
336318
}
337319

338320
outputDatabase.ifPresent(val -> out.append("db", val));
339-
outputSharded.ifPresent(val -> out.append("sharded", val));
340321

341322
return out;
342323
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/DefaultMongoHandlerObservationConvention.java

-13
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
import io.micrometer.common.KeyValues;
1919

20-
import java.net.InetSocketAddress;
21-
2220
import org.springframework.data.mongodb.observability.MongoObservation.LowCardinalityCommandKeyNames;
23-
import org.springframework.data.mongodb.util.MongoCompatibilityAdapter;
2421
import org.springframework.util.ObjectUtils;
2522

2623
import com.mongodb.ConnectionString;
@@ -78,16 +75,6 @@ public KeyValues getLowCardinalityKeyValues(MongoHandlerContext context) {
7875
keyValues = keyValues.and(LowCardinalityCommandKeyNames.NET_TRANSPORT.withValue("IP.TCP"),
7976
LowCardinalityCommandKeyNames.NET_PEER_NAME.withValue(serverAddress.getHost()),
8077
LowCardinalityCommandKeyNames.NET_PEER_PORT.withValue("" + serverAddress.getPort()));
81-
82-
InetSocketAddress socketAddress = MongoCompatibilityAdapter.serverAddressAdapter(serverAddress)
83-
.getSocketAddress();
84-
85-
if (socketAddress != null) {
86-
87-
keyValues = keyValues.and(
88-
LowCardinalityCommandKeyNames.NET_SOCK_PEER_ADDR.withValue(socketAddress.getHostName()),
89-
LowCardinalityCommandKeyNames.NET_SOCK_PEER_PORT.withValue("" + socketAddress.getPort()));
90-
}
9178
}
9279

9380
ConnectionId connectionId = connectionDescription.getConnectionId();

0 commit comments

Comments
 (0)