Skip to content

Restrict implicit id mapping to document types - #5191

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

Restrict implicit id mapping to document types#5191
DragonFSKY wants to merge 1 commit into
spring-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>
@christophstrobl

Copy link
Copy Markdown
Member

Sorry for long silence and thank you @DragonFSKY for the PR and your patience. looks good so far.

@christophstrobl christophstrobl removed the status: waiting-for-triage An issue we've not yet triaged label Jun 29, 2026
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 29, 2026
@mp911de
mp911de force-pushed the main branch 2 times, most recently from cc9055c to 9535e9c Compare August 5, 2026 14:13
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]

3 participants