You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DATAMONGO-1412 - Fix backticks and code element highlighting.
Fixed broken highlighting using backticks followed by chars/single quotes. Convert single quote emphasis of id to backtick code fences. Add missing spaces between words and backticks.
Original Pull Request: #359
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/mapping.adoc
+18-18Lines changed: 18 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -12,25 +12,25 @@ NOTE: `SimpleMongoConverter` has been deprecated in Spring Data MongoDB M3 as al
12
12
13
13
`MongoMappingConverter` has a few conventions for mapping objects to documents when no additional mapping metadata is provided. The conventions are:
14
14
15
-
* The short Java class name is mapped to the collection name in the following manner. The class '`com.bigbank.SavingsAccount`' maps to '`savingsAccount`' collection name.
15
+
* The short Java class name is mapped to the collection name in the following manner. The class `com.bigbank.SavingsAccount` maps to `savingsAccount` collection name.
16
16
* All nested objects are stored as nested objects in the document and *not* as DBRefs
17
17
* The converter will use any Spring Converters registered with it to override the default mapping of object properties to document field/values.
18
18
* The fields of an object are used to convert to and from fields in the document. Public JavaBean properties are not used.
19
19
* You can have a single non-zero argument constructor whose constructor argument names match top level field names of document, that constructor will be used. Otherwise the zero arg constructor will be used. if there is more than one non-zero argument constructor an exception will be thrown.
20
20
21
21
[[mapping.conventions.id-field]]
22
-
=== How the '_id' field is handled in the mapping layer
22
+
=== How the `_id` field is handled in the mapping layer
23
23
24
-
MongoDB requires that you have an '_id' field for all documents. If you don't provide one the driver will assign a ObjectId with a generated value. The "_id" field can be of any type the, other than arrays, so long as it is unique. The driver naturally supports all primitive types and Dates. When using the `MongoMappingConverter` there are certain rules that govern how properties from the Java class is mapped to this '_id' field.
24
+
MongoDB requires that you have an `_id` field for all documents. If you don't provide one the driver will assign a ObjectId with a generated value. The "_id" field can be of any type the, other than arrays, so long as it is unique. The driver naturally supports all primitive types and Dates. When using the `MongoMappingConverter` there are certain rules that govern how properties from the Java class is mapped to this `_id` field.
25
25
26
-
The following outlines what field will be mapped to the '_id' document field:
26
+
The following outlines what field will be mapped to the `_id` document field:
27
27
28
-
* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the '_id' field.
29
-
* A field without an annotation but named 'id' will be mapped to the '_id' field.
30
-
* The default field name for identifiers is '_id' and can be customized via the `@Field` annotation.
28
+
* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the `_id` field.
29
+
* A field without an annotation but named `id` will be mapped to the `_id` field.
30
+
* The default field name for identifiers is `_id` and can be customized via the `@Field` annotation.
31
31
32
32
[cols="1,2", options="header"]
33
-
.Examples for the translation of '_id'-field definitions
33
+
.Examples for the translation of `_id` field definitions
34
34
|===
35
35
| Field definition
36
36
| Resulting Id-Fieldname in MongoDB
@@ -41,21 +41,21 @@ The following outlines what field will be mapped to the '_id' document field:
41
41
| `@Field` `String` id
42
42
| `_id`
43
43
44
-
| `@Field('x')` `String` id
44
+
| `@Field("x")` `String` id
45
45
| `x`
46
46
47
47
| `@Id` `String` x
48
48
| `_id`
49
49
50
-
| `@Field('x')` `@Id` `String` x
50
+
| `@Field("x")` `@Id` `String` x
51
51
| `_id`
52
52
|===
53
53
54
54
The following outlines what type conversion, if any, will be done on the property mapped to the _id document field.
55
55
56
-
* If a field named 'id' is declared as a String or BigInteger in the Java class it will be converted to and stored as an ObjectId if possible. ObjectId as a field type is also valid. If you specify a value for 'id' in your application, the conversion to an ObjectId is detected to the MongoDBdriver. If the specified 'id' value cannot be converted to an ObjectId, then the value will be stored as is in the document's _id field.
57
-
* If a field named ' id' id field is not declared as a String, BigInteger, or ObjectID in the Java class then you should assign it a value in your application so it can be stored 'as-is' in the document's _id field.
58
-
* If no field named 'id' is present in the Java class then an implicit '_id' file will be generated by the driver but not mapped to a property or field of the Java class.
56
+
* If a field named `id` is declared as a String or BigInteger in the Java class it will be converted to and stored as an ObjectId if possible. ObjectId as a field type is also valid. If you specify a value for `id` in your application, the conversion to an ObjectId is detected to the MongoDBdriver. If the specified `id` value cannot be converted to an ObjectId, then the value will be stored as is in the document's _id field.
57
+
* If a field named `id` id field is not declared as a String, BigInteger, or ObjectID in the Java class then you should assign it a value in your application so it can be stored 'as-is' in the document's _id field.
58
+
* If no field named `id` is present in the Java class then an implicit `_id` file will be generated by the driver but not mapped to a property or field of the Java class.
59
59
60
60
When querying and updating `MongoTemplate` will use the converter to handle conversions of the `Query` and `Update` objects that correspond to the above rules for saving documents so field names and types used in your queries will be able to match what is in your domain classes.
61
61
@@ -292,11 +292,11 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration {
292
292
----
293
293
====
294
294
295
-
`AbstractMongoConfiguration` requires you to implement methods that define a `com.mongodb.Mongo` as well as provide a database name. `AbstractMongoConfiguration` also has a method you can override named '`getMappingBasePackage`' which tells the converter where to scan for classes annotated with the `@org.springframework.data.mongodb.core.mapping.Document` annotation.
295
+
`AbstractMongoConfiguration` requires you to implement methods that define a `com.mongodb.Mongo` as well as provide a database name. `AbstractMongoConfiguration` also has a method you can override named `getMappingBasePackage(…)` which tells the converter where to scan for classes annotated with the `@Document` annotation.
296
296
297
-
You can add additional converters to the converter by overriding the method afterMappingMongoConverterCreation. Also shown in the above example is a `LoggingEventListener` which logs `MongoMappingEvent`s that are posted onto Spring's `ApplicationContextEvent` infrastructure.
297
+
You can add additional converters to the converter by overriding the method afterMappingMongoConverterCreation. Also shown in the above example is a `LoggingEventListener` which logs `MongoMappingEvent`s that are posted onto Spring's `ApplicationContextEvent` infrastructure.
298
298
299
-
NOTE: AbstractMongoConfiguration will create a MongoTemplate instance and registered with the container under the name 'mongoTemplate'.
299
+
NOTE: AbstractMongoConfiguration will create a MongoTemplate instance and registered with the container under the name `mongoTemplate`.
300
300
301
301
You can also override the method `UserCredentials getUserCredentials()` to provide the username and password information to connect to the database.
302
302
@@ -349,7 +349,7 @@ The `base-package` property tells it where to scan for classes annotated with th
349
349
[[mapping-usage]]
350
350
== Metadata based Mapping
351
351
352
-
To take full advantage of the object mapping functionality inside the Spring Data/MongoDB support, you should annotate your mapped objects with the `@org.springframework.data.mongodb.core.mapping.Document` annotation. Although it is not necessary for the mapping framework to have this annotation (your POJOs will be mapped correctly, even without any annotations), it allows the classpath scanner to find and pre-process your domain objects to extract the necessary metadata. If you don't use this annotation, your application will take a slight performance hit the first time you store a domain object because the mapping framework needs to build up its internal metadata model so it knows about the properties of your domain object and how to persist them.
352
+
To take full advantage of the object mapping functionality inside the Spring Data/MongoDB support, you should annotate your mapped objects with the `@Document` annotation. Although it is not necessary for the mapping framework to have this annotation (your POJOs will be mapped correctly, even without any annotations), it allows the classpath scanner to find and pre-process your domain objects to extract the necessary metadata. If you don't use this annotation, your application will take a slight performance hit the first time you store a domain object because the mapping framework needs to build up its internal metadata model so it knows about the properties of your domain object and how to persist them.
353
353
354
354
.Example domain object
355
355
====
@@ -599,7 +599,7 @@ Simply declaring these beans in your Spring ApplicationContext will cause them t
599
599
[[mapping-explicit-converters]]
600
600
=== Overriding Mapping with explicit Converters
601
601
602
-
When storing and querying your objects it is convenient to have a `MongoConverter` instance handle the mapping of all Java types to DBObjects. However, sometimes you may want the `MongoConverter`'s do most of the work but allow you to selectively handle the conversion for a particular type or to optimize performance.
602
+
When storing and querying your objects it is convenient to have a `MongoConverter` instance handle the mapping of all Java types to DBObjects. However, sometimes you may want the `MongoConverter`s do most of the work but allow you to selectively handle the conversion for a particular type or to optimize performance.
603
603
604
604
To selectively handle the conversion yourself, register one or more one or more `org.springframework.core.convert.converter.Converter` instances with the MongoConverter.
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/mongo-repositories.adoc
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ public class Person {
28
28
----
29
29
====
30
30
31
-
We have a quite simple domain object here. Note that it has a property named `id` of type`ObjectId`. The default serialization mechanism used in `MongoTemplate` (which is backing the repository support) regards properties named id as document id. Currently we support`String`, `ObjectId` and `BigInteger` as id-types.
31
+
We have a quite simple domain object here. Note that it has a property named `id` of type`ObjectId`. The default serialization mechanism used in `MongoTemplate` (which is backing the repository support) regards properties named id as document id. Currently we support`String`, `ObjectId` and `BigInteger` as id-types.
32
32
33
33
.Basic repository interface to persist Person entities
34
34
====
@@ -99,7 +99,7 @@ class ApplicationConfig extends AbstractMongoConfiguration {
99
99
----
100
100
====
101
101
102
-
As our domain repository extends `PagingAndSortingRepository` it provides you with CRUD operations as well as methods for paginated and sorted access to the entities. Working with the repository instance is just a matter of dependency injecting it into a client. So accessing the second page of `Person`s at a page size of 10 would simply look something like this:
102
+
As our domain repository extends `PagingAndSortingRepository` it provides you with CRUD operations as well as methods for paginated and sorted access to the entities. Working with the repository instance is just a matter of dependency injecting it into a client. So accessing the second page of `Person`s at a page size of 10 would simply look something like this:
103
103
104
104
.Paging access to Person entities
105
105
====
@@ -139,17 +139,17 @@ public interface PersonRepository extends PagingAndSortingRepository<Person, Str
Person findByShippingAddresses(Address address); <3>
142
-
142
+
143
143
Stream<Person> findAllBy(); <4>
144
144
}
145
145
----
146
146
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
147
147
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly.
148
-
<3> Shows that you can query based on properties which are not a primitive type.
148
+
<3> Shows that you can query based on properties which are not a primitive type.
149
149
<4> Uses a Java 8 `Stream` which reads and converts individual elements while iterating the stream.
150
150
====
151
151
152
-
152
+
153
153
154
154
NOTE: Note that for version 1.0 we currently don't support referring to parameters that are mapped as `DBRef` in the domain class.
155
155
@@ -328,7 +328,7 @@ public interface PersonRepository extends MongoRepository<Person, String>
0 commit comments