Browse Source

make it beautiful

labs/antora
Christoph Strobl 2 years ago
parent
commit
823e0d02fc
No known key found for this signature in database
GPG Key ID: 8CC1AB53391458C8
  1. 2
      src/main/antora/modules/ROOT/examples/ReactiveMongoApplication.java
  2. 41
      src/main/antora/modules/ROOT/nav.adoc
  3. 13
      src/main/antora/modules/ROOT/pages/migration-guide/migration-guide-2.x-to-3.x.adoc
  4. 2
      src/main/antora/modules/ROOT/pages/migration-guide/migration-guide-3.x-to-4.x.adoc
  5. 2
      src/main/antora/modules/ROOT/pages/mongodb/auditing.adoc
  6. 11
      src/main/antora/modules/ROOT/pages/mongodb/client-session-transactions.adoc
  7. 44
      src/main/antora/modules/ROOT/pages/mongodb/configuration.adoc
  8. 3
      src/main/antora/modules/ROOT/pages/mongodb/mapping/mapping.adoc
  9. 63
      src/main/antora/modules/ROOT/pages/mongodb/migrating.adoc
  10. 2
      src/main/antora/modules/ROOT/pages/mongodb/mongo-encryption.adoc
  11. 2
      src/main/antora/modules/ROOT/pages/mongodb/tailable-cursors.adoc
  12. 4
      src/main/antora/modules/ROOT/pages/mongodb/template-api.adoc

2
src/main/antora/modules/ROOT/examples/ReactiveMongoApplication.java

@ -30,7 +30,7 @@ public class ReactiveMongoApplication { @@ -30,7 +30,7 @@ public class ReactiveMongoApplication {
ReactiveMongoOperations mongoOps = new ReactiveMongoTemplate(MongoClients.create(), "database");
Mono<Person> joe = mongoOps.insert(new Person("Joe", 34))
mongoOps.insert(new Person("Joe", 34))
.then(mongoOps.query(Person.class).matching(where("name").is("Joe")).first())
.doOnNext(System.out::println)
.block();

41
src/main/antora/modules/ROOT/nav.adoc

@ -7,8 +7,6 @@ @@ -7,8 +7,6 @@
* xref:mongodb.adoc[]
** xref:mongodb/getting-started.adoc[]
** xref:mongodb/configuration.adoc[]
// Template
** xref:mongodb/template-api.adoc[]
*** xref:mongodb/template-config.adoc[]
*** xref:mongodb/template-crud-operations.adoc[]
@ -18,10 +16,7 @@ @@ -18,10 +16,7 @@
*** xref:mongodb/aggregation-framework.adoc[]
*** xref:mongodb/template-collection-management.adoc[]
**** xref:mongodb/template-collection-schema.adoc[]
** xref:mongodb/template-gridfs.adoc[]
// Mapping
*** xref:mongodb/template-gridfs.adoc[]
** xref:mongodb/mapping/mapping.adoc[]
*** xref:mongodb/mapping/custom-conversions.adoc[]
*** xref:mongodb/mapping/property-converters.adoc[]
@ -29,7 +24,13 @@ @@ -29,7 +24,13 @@
*** xref:mongodb/mapping/document-references.adoc[]
*** xref:mongodb/mapping/entity-callbacks.adoc[]
*** xref:mongodb/mapping/lifecycle-events.adoc[]
** xref:mongodb/client-session-transactions.adoc[]
** xref:mongodb/change-streams.adoc[]
** xref:mongodb/tailable-cursors.adoc[]
** xref:mongodb/sharding.adoc[]
** xref:mongodb/mongo-encryption.adoc[]
** xref:mongodb/auditing.adoc[]
** xref:mongodb/observability.adoc[]
// Repository
* xref:repositories.adoc[]
@ -49,14 +50,6 @@ @@ -49,14 +50,6 @@
* xref:observability.adoc[]
// Mongo Specifics
** xref:mongodb/client-session-transactions.adoc[]
** xref:mongodb/tailable-cursors.adoc[]
** xref:mongodb/change-streams.adoc[]
** xref:mongodb/observability.adoc[]
** xref:mongodb/sharding.adoc[]
** xref:mongodb/mongo-encryption.adoc[]
* xref:kotlin.adoc[]
** xref:kotlin/requirements.adoc[]
** xref:kotlin/null-safety.adoc[]
@ -66,13 +59,13 @@ @@ -66,13 +59,13 @@
// move parts somewhere else
** xref:mongodb/query-by-example.adoc[]
**** xref:mongodb/mongo-query/geo-json.adoc[]
**** xref:mongodb/mongo-query/collation.adoc[]
**** xref:mongodb/mongo-query/kotlin-support.adoc[]
**** xref:mongodb/mongo-query/additional-options.adoc[]
// still needed???
*** xref:mongodb/mongo-mapreduce.adoc[]
*** xref:mongodb/mongo-server-side-scripts.adoc[]
*** xref:mongodb/mongo-group.adoc[]
// ** xref:mongodb/query-by-example.adoc[]
// **** xref:mongodb/mongo-query/geo-json.adoc[]
// **** xref:mongodb/mongo-query/collation.adoc[]
// **** xref:mongodb/mongo-query/kotlin-support.adoc[]
// **** xref:mongodb/mongo-query/additional-options.adoc[]
//
// // still needed???
// *** xref:mongodb/mongo-mapreduce.adoc[]
// *** xref:mongodb/mongo-server-side-scripts.adoc[]
// *** xref:mongodb/mongo-group.adoc[]

13
src/main/antora/modules/ROOT/pages/migration-guide/migration-guide-2.x-to-3.x.adoc

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
[[mongodb.migration.2.x-3.x]]
== Migration Guide from 2.x to 3.x
= 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 https://www.mongodb.com/docs/drivers/java/sync/current/upgrade/[MongoDB Documentation].
[[dependency-changes]]
=== Dependency Changes
== Dependency Changes
* `org.mongodb:mongo-java-driver` (uber jar) got replaced with:
** bson-jar
@ -16,7 +16,7 @@ The change in dependencies allows usage of the reactive support without having t @@ -16,7 +16,7 @@ The change in dependencies allows usage of the reactive support without having t
NOTE: The new sync driver does no longer support `com.mongodb.DBObject`. Please use `org.bson.Document` instead.
[[signature-changes]]
=== Signature Changes
== Signature Changes
* `MongoTemplate` no longer supports `com.mongodb.MongoClient` and `com.mongodb.MongoClientOptions`.
Please use `com.mongodb.client.MongoClient` and `com.mongodb.MongoClientSettings` instead.
@ -24,18 +24,20 @@ Please use `com.mongodb.client.MongoClient` and `com.mongodb.MongoClientSettings @@ -24,18 +24,20 @@ Please use `com.mongodb.client.MongoClient` and `com.mongodb.MongoClientSettings
In case you're using `AbstractMongoConfiguration` please switch to `AbstractMongoClientConfiguration`.
[[namespace-changes]]
=== Namespace Changes
== 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 https://docs.mongodb.com/manual/reference/connection-string/[MongoDB Documentation] for details.
[source,xml]
====
[source,xml]
----
<mongo:mongo.mongo-client id="with-defaults" />
----
[source,xml]
----
<context:property-placeholder location="classpath:..."/>
@ -46,6 +48,7 @@ Please see the https://docs.mongodb.com/manual/reference/connection-string/[Mong @@ -46,6 +48,7 @@ Please see the https://docs.mongodb.com/manual/reference/connection-string/[Mong
connection-string="mongodb://${mongo.host}:${mongo.port}/?replicaSet=rs0" />
----
[source,xml]
----
<mongo:mongo.mongo-client id="client-with-settings" replica-set="rs0">
<mongo:client-settings cluster-connection-mode="MULTIPLE"

2
src/main/antora/modules/ROOT/pages/migration-guide/migration-guide-3.x-to-4.x.adoc

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
[[mongodb.migration.3.x-4.x]]
== Migration Guide from 3.x to 4.x
= Migration Guide from 3.x to 4.x
Spring Data MongoDB 4.x requires the MongoDB Java Driver 4.8.x +
To learn more about driver versions please visit the https://www.mongodb.com/docs/drivers/java/sync/current/upgrade/[MongoDB Documentation].

2
src/main/antora/modules/ROOT/pages/mongodb/auditing.adoc

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
[[mongo.auditing]]
= General Auditing Configuration for MongoDB
= Auditing
Since Spring Data MongoDB 1.4, auditing can be enabled by annotating a configuration class with the `@EnableMongoAuditing` annotation, as the following example shows:

11
src/main/antora/modules/ROOT/pages/mongodb/client-session-transactions.adoc

@ -1,11 +1,16 @@ @@ -1,11 +1,16 @@
[[mongo.sessions]]
= MongoDB Sessions
= Sessions & Transactions
As of version 3.6, MongoDB supports the concept of sessions. The use of sessions enables MongoDB's https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#causal-consistency[Causal Consistency] model, which guarantees running operations in an order that respects their causal relationships. Those are split into `ServerSession` instances and `ClientSession` instances. In this section, when we speak of a session, we refer to `ClientSession`.
As of version 3.6, MongoDB supports the concept of sessions.
The use of sessions enables MongoDB's https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#causal-consistency[Causal Consistency] model, which guarantees running operations in an order that respects their causal relationships.
Those are split into `ServerSession` instances and `ClientSession` instances.
In this section, when we speak of a session, we refer to `ClientSession`.
WARNING: Operations within a client session are not isolated from operations outside the session.
Both `MongoOperations` and `ReactiveMongoOperations` provide gateway methods for tying a `ClientSession` to the operations. `MongoCollection` and `MongoDatabase` use session proxy objects that implement MongoDB's collection and database interfaces, so you need not add a session on each call. This means that a potential call to `MongoCollection#find()` is delegated to `MongoCollection#find(ClientSession)`.
Both `MongoOperations` and `ReactiveMongoOperations` provide gateway methods for tying a `ClientSession` to the operations.
`MongoCollection` and `MongoDatabase` use session proxy objects that implement MongoDB's collection and database interfaces, so you need not add a session on each call.
This means that a potential call to `MongoCollection#find()` is delegated to `MongoCollection#find(ClientSession)`.
NOTE: Methods such as `(Reactive)MongoOperations#getCollection` return native MongoDB Java Driver gateway objects (such as `MongoCollection`) that themselves offer dedicated methods for `ClientSession`. These methods are *NOT* session-proxied. You should provide the `ClientSession` where needed when interacting directly with a `MongoCollection` or `MongoDatabase` and not through one of the `#execute` callbacks on `MongoOperations`.

44
src/main/antora/modules/ROOT/pages/mongodb/configuration.adoc

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
[[mongodb-connectors]]
= Connecting to MongoDB with Spring
= Connecting to MongoDB
One of the first tasks when using MongoDB and Spring is to create a `MongoClient` object using the IoC container.
There are two main ways to do this, either by using Java-based bean metadata or by using XML-based bean metadata.
@ -171,8 +171,7 @@ public class MongoApplication { @@ -171,8 +171,7 @@ public class MongoApplication {
}
----
The code in bold highlights the use of `SimpleMongoClientDbFactory` and is the only difference between the listing shown in the xref:mongodb/getting-started.adoc[getting started section].
NOTE: Use `SimpleMongoClientDbFactory` when choosing `com.mongodb.client.MongoClient` as the entrypoint of choice.
Use `SimpleMongoClientDbFactory` when choosing `com.mongodb.client.MongoClient` as the entrypoint of choice.
Reactive::
+
@ -232,12 +231,14 @@ MongoDB Server generation 3 changed the authentication model when connecting to @@ -232,12 +231,14 @@ MongoDB Server generation 3 changed the authentication model when connecting to
Therefore, some of the configuration options available for authentication are no longer valid.
You should use the `MongoClient`-specific options for setting credentials through `MongoCredential` to provide authentication data, as shown in the following example:
====
.Java
[source,java,role="primary"]
[tabs]
======
Java::
+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
----
@Configuration
public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientConfiguration {
public class MongoAppConfig extends AbstractMongoClientConfiguration {
@Override
public String getDatabaseName() {
@ -256,28 +257,29 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientCo @@ -256,28 +257,29 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientCo
}
----
.XML
[source,xml,role="secondary"]
XML::
+
[source,xml,indent=0,subs="verbatim,quotes",role="secondary"]
----
<mongo:db-factory dbname="database" />
----
====
NOTE: Username and password credentials used in XML-based configuration must be URL-encoded when these contain reserved characters, such as `:`, `%`, `@`, or `,`.
Username and password credentials used in XML-based configuration must be URL-encoded when these contain reserved characters, such as `:`, `%`, `@`, or `,`.
The following example shows encoded credentials:
`m0ng0@dmin:mo_res:bw6},Qsdxx@admin@database` -> `m0ng0%40dmin:mo_res%3Abw6%7D%2CQsdxx%40admin@database`
See https://tools.ietf.org/html/rfc3986#section-2.2[section 2.2 of RFC 3986] for further details.
======
If you need to configure additional options on the `com.mongodb.client.MongoClient` instance that is used to create a `SimpleMongoClientDbFactory`, you can refer to an existing bean as shown in the following example. To show another common usage pattern, the following listing shows the use of a property placeholder, which lets you parametrize the configuration and the creation of a `MongoTemplate`:
====
.Java
[source,java,role="primary"]
[tabs]
======
Java::
+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
----
@Configuration
@PropertySource("classpath:/com/myapp/mongodb/config/mongo.properties")
public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientConfiguration {
public class MongoAppConfig extends AbstractMongoClientConfiguration {
@Autowired
Environment env;
@ -309,8 +311,9 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientCo @@ -309,8 +311,9 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientCo
}
----
.XML
[source,xml,role="secondary"]
XML::
+
[source,xml,indent=0,subs="verbatim,quotes",role="secondary"]
----
<context:property-placeholder location="classpath:/com/myapp/mongodb/config/mongo.properties"/>
@ -330,5 +333,4 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientCo @@ -330,5 +333,4 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoClientCo
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
----
====
======

3
src/main/antora/modules/ROOT/pages/mongodb/mapping/mapping.adoc

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
[[mapping-chapter]]
= Mapping
= Object Mapping
Rich mapping support is provided by the `MappingMongoConverter`. `MappingMongoConverter` has a rich metadata model that provides a full feature set to map domain objects to MongoDB documents.
The mapping metadata model is populated by using annotations on your domain objects.

63
src/main/antora/modules/ROOT/pages/mongodb/migrating.adoc

@ -1,63 +0,0 @@ @@ -1,63 +0,0 @@
[[migrating]]
= Migrating
This chapter coverts major changes and outlines migration steps.
[[migrating-2.x-to-3.0]]
== 2.x to 3.0
[[dependency-changes]]
=== 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]]
=== Signature Changes
* `MongoTemplate` no longer supports `com.mongodb.MongoClient` and `com.mongodb.MongoClientOptions`.
Please use `com.mongodb.client.MongoClient` and `com.mongodb.MongoClientSettings` instead.
In case you're using `AbstractMongoConfiguration` please switch to `AbstractMongoClientConfiguration`.
[[namespace-changes]]
=== 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 https://docs.mongodb.com/manual/reference/connection-string/[MongoDB Documentation] for details.
[source,xml]
====
----
<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>
----
====

2
src/main/antora/modules/ROOT/pages/mongodb/mongo-encryption.adoc

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
[[mongo.encryption]]
= Client Side Field Level Encryption (CSFLE)
= Encryption (CSFLE)
Client Side Encryption is a feature that encrypts data in your application before it is sent to MongoDB.
We recommend you get familiar with the concepts, ideally from the https://www.mongodb.com/docs/manual/core/csfle/[MongoDB Documentation] to learn more about its capabilities and restrictions before you continue applying Encryption through Spring Data.

2
src/main/antora/modules/ROOT/pages/mongodb/tailable-cursors.adoc

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// carry over the old bookmarks to prevent external links from failing
[[tailable-cursors]]
= [[mongo.reactive.repositories.infinite-streams]] Infinite Streams with Tailable Cursors
= Tailable Cursors
By default, MongoDB automatically closes a cursor when the client exhausts all results supplied by the cursor.
Closing a cursor on exhaustion turns a stream into a finite stream. For https://docs.mongodb.com/manual/core/capped-collections/[capped collections],

4
src/main/antora/modules/ROOT/pages/mongodb/template-api.adoc

@ -1,13 +1,11 @@ @@ -1,13 +1,11 @@
[[mongo-template]]
= Introduction to `MongoTemplate`
= Template API
The `MongoTemplate` and its reactive counterpart class, located in the `org.springframework.data.mongodb.core` package, is the central class of Spring's MongoDB support and provides a rich feature set for interacting with the database.
The template offers convenience operations to create, update, delete, and query MongoDB documents and provides a mapping between your domain objects and MongoDB documents.
NOTE: Once configured, `MongoTemplate` is thread-safe and can be reused across multiple instances.
== Template API
The `MongoTemplate` class implements the interface `MongoOperations`.
In as much as possible, the methods on `MongoOperations` are named after methods available on the MongoDB driver `Collection` object, to make the API familiar to existing MongoDB developers who are used to the driver API.
For example, you can find methods such as `find`, `findAndModify`, `findAndReplace`, `findOne`, `insert`, `remove`, `save`, `update`, and `updateMulti`.

Loading…
Cancel
Save