spring-projects / spring-projects/spring-data-mongodb

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

Open
#3,351 10 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: mapping status: ideal-for-contribution type: bug
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

provirus opened DATAMONGO-2496 and commented

Having the following classes:

@Document
class Parent {
  @Id
  private String id;

  private Child child;

  // Getters and setters
}

class Child {
  private Long id;
  private String name;

  // Getters and setters
}

Spring Data produces the following document:

{
  "_id": ...,
  "child": {
    "_id": 10,
    "name": "Foo"
  }
}

 
The expected document is:

{
  "_id": ...,
  "child": {
    "id": 10,
    "name": "Foo"
  }
}

Since there is no need for id mapping on the child document


Affects: 2.2.5 (Moore SR5)

Issue Links:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the mapping with the Parent and Child classes shown in the issue, comparing the nested document with the expected JSON. Trace the MongoDB mapping path that handles the child’s id and confirm that the parent still uses _id while the nested child retains id. Done means the reported nested output matches the expected document.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.