DATAMONGO-1158 - Polishing.
MongoFactoryBean, MongoOptionsFactoryBean, MongoClientFactoryBean and MongoClientOptionsFactoryBean now extend AbstractFactoryBean to get a lot of the lifecycle callbacks without further code. Added non-null assertions to newly introduced methods on MongoOperations/MongoTemplate. Moved MongoClientVersion into util package. Introduced static imports for ReflectionUtils and MongoClientVersion for all references in the newly introduced Invoker types. Some formatting, JavaDoc polishes, suppress deprecation warnings. Added build profile for MongoDB Java driver 3.0 as well as the following snapshot. Original pull request: #273.
This commit is contained in:
@@ -190,7 +190,7 @@ public class Person {
|
||||
----
|
||||
====
|
||||
|
||||
IMPORTANT: The `@Id` annotation tells the mapper which property you want to use for the MongoDB `_id` property and the `@Indexed` annotation tells the mapping framework to call `createIndex` on that property of your document, making searches faster.
|
||||
IMPORTANT: The `@Id` annotation tells the mapper which property you want to use for the MongoDB `_id` property and the `@Indexed` annotation tells the mapping framework to call `createIndex(…)` on that property of your document, making searches faster.
|
||||
|
||||
IMPORTANT: Automatic index creation is only done for types annotated with `@Document`.
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
[[mongo.mongo-3]]
|
||||
= MongoDB 3.0 Support
|
||||
|
||||
Spring Data MongoDB allows usage of both _mongo-java-driver_ generations 2 and 3 when connecting to a MongoDB 2.6/3.0 server running _MMap.v1_ or a MongoDB server 3.0 using _MMap.v1_ or the _WiredTiger_ storage engine.
|
||||
Spring Data MongoDB allows usage of both MongoDB Java driver generations 2 and 3 when connecting to a MongoDB 2.6/3.0 server running _MMap.v1_ or a MongoDB server 3.0 using _MMap.v1_ or the _WiredTiger_ storage engine.
|
||||
|
||||
NOTE: Please refer to the driver and database specific documentation for major differences between those.
|
||||
|
||||
NOTE: Operations that are no longer valid using a 3.x mongo-java-driver have been deprecated within Spring Data and will be removed in a subsequent release.
|
||||
|
||||
[[mongodb:mongo-3-configuration]]
|
||||
NOTE: Operations that are no longer valid using a 3.x MongoDB Java driver have been deprecated within Spring Data and will be removed in a subsequent release.
|
||||
|
||||
== Using Spring Data MongoDB with MongoDB 3.0
|
||||
|
||||
[[mongo.mongo-3.configuration]]
|
||||
=== Configuration Options
|
||||
|
||||
Some of the configuration options have been changed / removed for the _mongo-java-driver_. The following options will be ignored using the generation 3 driver:
|
||||
@@ -17,7 +17,7 @@ Some of the configuration options have been changed / removed for the _mongo-jav
|
||||
* autoConnectRetry
|
||||
* maxAutoConnectRetryTime
|
||||
* slaveOk
|
||||
|
||||
|
||||
Generally it is recommended to use the `<mongo:mongo-client ... />` and `<mongo:client-options ... />` elements instead of `<mongo:mongo ... />` when doing XML based configuration, since those elements will only provide you with attributes valid for the 3 generation java driver.
|
||||
|
||||
[source,xml]
|
||||
@@ -28,7 +28,7 @@ Generally it is recommended to use the `<mongo:mongo-client ... />` and `<mongo:
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
|
||||
<mongo:mongo-client host="127.0.0.1" port="27017">
|
||||
<mongo:client-options write-concern="NORMAL" />
|
||||
</mongo:mongo-client>
|
||||
@@ -36,10 +36,12 @@ Generally it is recommended to use the `<mongo:mongo-client ... />` and `<mongo:
|
||||
</beans>
|
||||
----
|
||||
|
||||
[[mongo.mongo-3.write-concern]]
|
||||
=== WriteConcern and WriteConcernChecking
|
||||
|
||||
The `WriteConcern.NONE`, which had been used as default by Spring Data MongoDB, was removed in 3.0. Therefore in a MongoDB 3 environment the `WriteConcern` will be defaulted to `WriteConcern.UNACKNOWLEGED`. In case `WriteResultChecking.EXCEPTION` is enabled the `WriteConcern` will be altered to `WriteConcern.ACKNOWLEDGED` for write operations, as otherwise errors during execution would not be throw correctly, since simply not raised by the driver.
|
||||
The `WriteConcern.NONE`, which had been used as default by Spring Data MongoDB, was removed in 3.0. Therefore in a MongoDB 3 environment the `WriteConcern` will be defaulted to `WriteConcern.UNACKNOWLEGED`. In case `WriteResultChecking.EXCEPTION` is enabled the `WriteConcern` will be altered to `WriteConcern.ACKNOWLEDGED` for write operations, as otherwise errors during execution would not be throw correctly, since simply not raised by the driver.
|
||||
|
||||
[[mongo.mongo-3.authentication]]
|
||||
=== Authentication
|
||||
|
||||
MongoDB Server generation 3 changed the authentication model when connecting to the DB. Therefore some of the configuration options available for authentication are no longer valid. Please use the `MongoClient` specific options for setting credentials via `MongoCredential` to provide authentication data.
|
||||
@@ -63,7 +65,7 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoConfigur
|
||||
}
|
||||
----
|
||||
|
||||
In order to use authentication with XML configuration use the `credentials` attribue on `<mongo-client>`.
|
||||
In order to use authentication with XML configuration use the `credentials` attribue on `<mongo-client>`.
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
@@ -73,12 +75,13 @@ In order to use authentication with XML configuration use the `credentials` attr
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
|
||||
<mongo:mongo-client credentials="user:password@database" />
|
||||
|
||||
</beans>
|
||||
----
|
||||
|
||||
[[mongo.mongo-3.misc]]
|
||||
=== Other things to be aware of
|
||||
|
||||
This section covers additional things to keep in mind when using the 3.0 driver.
|
||||
@@ -86,8 +89,7 @@ This section covers additional things to keep in mind when using the 3.0 driver.
|
||||
* `IndexOperations.resetIndexCache()` is no longer supported.
|
||||
* Any `MapReduceOptions.extraOption` is silently ignored.
|
||||
* `WriteResult` does not longer hold error informations but throws an Exception.
|
||||
* `MongoOperations.executeInSession()` no longer calls `requestStart` / `requestDone`.
|
||||
* `MongoOperations.executeInSession(…)` no longer calls `requestStart` / `requestDone`.
|
||||
* Index name generation has become a driver internal operations, still we use the 2.x schema to generate names.
|
||||
* Some Exception messages differ between the generation 2 and 3 servers as well as between _MMap.v1_ and _WiredTiger_ storage engine.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user