From 870f383d224aa19a946fcbbcb7de29fe339e09c2 Mon Sep 17 00:00:00 2001 From: Renke Christian von Seggern Date: Fri, 19 Apr 2024 08:01:02 +0200 Subject: [PATCH] Polishing. Various typo fixes and wording improvements. --- .../ROOT/pages/mongodb/mapping/mapping.adoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/antora/modules/ROOT/pages/mongodb/mapping/mapping.adoc b/src/main/antora/modules/ROOT/pages/mongodb/mapping/mapping.adoc index 58c2eb1443..92ea59cd24 100644 --- a/src/main/antora/modules/ROOT/pages/mongodb/mapping/mapping.adoc +++ b/src/main/antora/modules/ROOT/pages/mongodb/mapping/mapping.adoc @@ -28,13 +28,13 @@ Public `JavaBean` properties are not used. [[mapping.conventions.id-field]] === How the `_id` field is handled in the mapping layer. -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. +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. The following outlines what field will be mapped to the `_id` document field: -* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the `_id` field. +* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the `_id` field. + +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`. * A field without an annotation but named `id` will be mapped to the `_id` field. -* The default field name for identifiers is `_id` and can be customized via the `@Field` annotation. [cols="1,2",options="header"] .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: | `@Id` `String` x | `_id` -| `@Field("x")` `@Id` `String` x -| `_id` +| `@Field("x")` `@Id` `String` y +| `x` |=== The following outlines what type conversion, if any, will be done on the property mapped to the _id document field. * 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 MongoDB driver. -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. +If you specify a value for `id` in your application, the conversion to an ObjectId is done by the MongoDB driver. +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. This also applies if the field is annotated with `@Id`. * If a field is annotated with `@MongoId` in the Java class it will be converted to and stored as using its actual type. No further conversion happens unless `@MongoId` declares a desired field type. If no value is provided for the `id` field, a new `ObjectId` will be created and converted to the properties type. * If a field is annotated with `@MongoId(FieldType.…)` in the Java class it will be attempted to convert the value to the declared `FieldType`. If no value is provided for the `id` field, a new `ObjectId` will be created and converted to the declared type. -* 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. +* 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. * 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. 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.