Skip to content

Restrict implicit id mapping to document types#5191

Open
DragonFSKY wants to merge 1 commit intospring-projects:mainfrom
DragonFSKY:GH-3351
Open

Restrict implicit id mapping to document types#5191
DragonFSKY wants to merge 1 commit intospring-projects:mainfrom
DragonFSKY:GH-3351

Conversation

@DragonFSKY
Copy link
Copy Markdown

Closes #3351

This PR introduces an opt-in setting on MongoMappingContext to restrict implicit id to _id mapping to types annotated with @Document.

The default remains unchanged to preserve the existing behavior for compatibility. Explicit @Id mappings continue to be recognized regardless of the owning type.

The change includes coverage for:

  • persistent property id detection
  • read/write mapping of root and nested values
  • query mapping of nested id paths
  • update mapping of nested id paths and values

Tested with:

./mvnw -s settings.xml -pl spring-data-mongodb clean test -Dtest=BasicMongoPersistentPropertyUnitTests,MappingMongoConverterUnitTests,QueryMapperUnitTests,UpdateMapperUnitTests

Checklist:

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided by the project and have not submitted unrelated formatting changes.
  • You submit test cases that back your changes.
  • You added yourself as author in the headers of the classes you touched.

Closes spring-projects#3351

Signed-off-by: dragonfsky <dragonfsky@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Id on nested documents are mapped to _id [DATAMONGO-2496]

2 participants