For the latest stable version, please use Spring Data MongoDB 4.4.0! |
Migration Guide from 2.x to 3.x
Spring Data MongoDB 3.x requires the MongoDB Java Driver 4.x
To learn more about driver versions please visit the MongoDB Documentation.
Dependency Changes
-
org.mongodb:mongo-java-driver
(uber jar) got replaced with:-
bson-jar
-
core-jar
-
sync-jar
-
The change in dependencies allows usage of the reactive support without having to pull the synchronous driver.
NOTE: The new sync driver does no longer support com.mongodb.DBObject
. Please use org.bson.Document
instead.
Signature Changes
-
MongoTemplate
no longer supportscom.mongodb.MongoClient
andcom.mongodb.MongoClientOptions
. Please usecom.mongodb.client.MongoClient
andcom.mongodb.MongoClientSettings
instead.
In case you’re using AbstractMongoConfiguration
please switch to AbstractMongoClientConfiguration
.
Namespace Changes
The switch to com.mongodb.client.MongoClient
requires an update of your configuration XML if you have one.
The best way to provide required connection information is by using a connection string.
Please see the MongoDB Documentation for details.
<mongo:mongo.mongo-client id="with-defaults" />
<context:property-placeholder location="classpath:..."/>
<mongo:mongo.mongo-client id="client-just-host-port"
host="${mongo.host}" port="${mongo.port}" />
<mongo:mongo.mongo-client id="client-using-connection-string"
connection-string="mongodb://${mongo.host}:${mongo.port}/?replicaSet=rs0" />
<mongo:mongo.mongo-client id="client-with-settings" replica-set="rs0">
<mongo:client-settings cluster-connection-mode="MULTIPLE"
cluster-type="REPLICA_SET"
cluster-server-selection-timeout="300"
cluster-local-threshold="100"
cluster-hosts="localhost:27018,localhost:27019,localhost:27020" />
</mongo:mongo.mongo-client>