From 504c44cdf3bcf8d75c9921c1b53972dd0edf2c51 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Mon, 2 Mar 2015 15:28:55 +0100 Subject: [PATCH] DATAMONGO-1081 - Improve documentation on field mapping semantics. Added table with examples to identifier field mapping section. Original pull request: #276. --- src/main/asciidoc/reference/mapping.adoc | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/asciidoc/reference/mapping.adoc b/src/main/asciidoc/reference/mapping.adoc index 94f50875a..9d9a88f9c 100644 --- a/src/main/asciidoc/reference/mapping.adoc +++ b/src/main/asciidoc/reference/mapping.adoc @@ -26,7 +26,30 @@ MongoDB requires that you have an '_id' field for all documents. If you don't pr 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 without an annotation but named `id` will be mapped to the '_id' field. +* 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 +|=== +| Field definition +| Resulting Id-Fieldname in MongoDB + +| `String` id +| `_id` + +| `@Field` `String` id +| `_id` + +| `@Field('x')` `String` id +| `x` + +| `@Id` `String` x +| `_id` + +| `@Field('x')` `@Id` `String` x +| `_id` +|=== The following outlines what type conversion, if any, will be done on the property mapped to the _id document field.