Skip to content

Commit 189ed6b

Browse files
Renke Christian von Seggernapp
Renke Christian von Seggern
authored and
app
committed
Polishing.
Various typo fixes and wording improvements. Closes spring-projects#4694
1 parent 414999a commit 189ed6b

File tree

1 file changed

+8
-8
lines changed
  • src/main/antora/modules/ROOT/pages/mongodb/mapping

1 file changed

+8
-8
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Public `JavaBean` properties are not used.
2828
[[mapping.conventions.id-field]]
2929
=== How the `_id` field is handled in the mapping layer.
3030

31-
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 `MappingMongoConverter` there are certain rules that govern how properties from the Java class is mapped to this `_id` field.
31+
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, other than arrays, so long as it is unique.The driver naturally supports all primitive types and Dates.When using the `MappingMongoConverter` there are certain rules that govern how properties from the Java class are mapped to the `_id` field.
3232

3333
The following outlines what field will be mapped to the `_id` document field:
3434

35-
* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the `_id` field.
35+
* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the `_id` field. +
36+
Additionally, the name of the document field can be customized via the `@Field` annotation, in which case the document will not contain a field `_id`.
3637
* A field without an annotation but named `id` will be mapped to the `_id` field.
37-
* The default field name for identifiers is `_id` and can be customized via the `@Field` annotation.
3838

3939
[cols="1,2",options="header"]
4040
.Examples for the translation of `_id` field definitions
@@ -54,23 +54,23 @@ The following outlines what field will be mapped to the `_id` document field:
5454
| `@Id` `String` x
5555
| `_id`
5656

57-
| `@Field("x")` `@Id` `String` x
58-
| `_id`
57+
| `@Field("x")` `@Id` `String` y
58+
| `x`
5959
|===
6060

6161
The following outlines what type conversion, if any, will be done on the property mapped to the _id document field.
6262

6363
* 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.
6464
ObjectId as a field type is also valid.
65-
If you specify a value for `id` in your application, the conversion to an ObjectId is detected to the MongoDB driver.
66-
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.
65+
If you specify a value for `id` in your application, the conversion to an ObjectId is done by the MongoDB driver.
66+
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.
6767
This also applies if the field is annotated with `@Id`.
6868
* If a field is annotated with `@MongoId` in the Java class it will be converted to and stored as using its actual type.
6969
No further conversion happens unless `@MongoId` declares a desired field type.
7070
If no value is provided for the `id` field, a new `ObjectId` will be created and converted to the properties type.
7171
* If a field is annotated with `@MongoId(FieldType.…)` in the Java class it will be attempted to convert the value to the declared `FieldType`.
7272
If no value is provided for the `id` field, a new `ObjectId` will be created and converted to the declared type.
73-
* 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.
73+
* If a field named `id` 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.
7474
* 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.
7575

7676
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.

0 commit comments

Comments
 (0)