從 2.x 遷移到 3.x 的指南

Spring Data MongoDB 3.x 需要 MongoDB Java 驅動 4.x
要了解更多關於驅動版本的資訊,請訪問 MongoDB 文件

依賴項變更

  • org.mongodb:mongo-java-driver(超大 JAR 包)已被替換為

    • bson-jar

    • core-jar

    • sync-jar

依賴項的變更允許使用響應式支援,而無需拉取同步驅動。注意:新的同步驅動不再支援 com.mongodb.DBObject。請改用 org.bson.Document

簽名變更

  • MongoTemplate 不再支援 com.mongodb.MongoClientcom.mongodb.MongoClientOptions。請改用 com.mongodb.client.MongoClientcom.mongodb.MongoClientSettings

如果您正在使用 AbstractMongoConfiguration,請切換到 AbstractMongoClientConfiguration

名稱空間變更

切換到 com.mongodb.client.MongoClient 需要更新您的配置 XML(如果有的話)。提供所需連線資訊的最佳方式是使用連線字串。請參閱 MongoDB 文件 獲取詳細資訊。

<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>
© . This site is unofficial and not affiliated with VMware.