Skip to content

Introduce @MongoId to customize Id conversion [DATAMONGO-1798] #2706

@spring-projects-issues

Description

@spring-projects-issues

Daniel Sass opened DATAMONGO-1798 and commented

Hi,

we're using Spring Boot 1.5.7 with the according MongoDB starter and have a collection where we use external ids as MongoDB _ids. This works fine unless we have ids with 24 digits. The ObjectMapper.convertId(Object id) checks if the id is a String and if the id is a valid object id with ObjectId.isValid(). The raw id is than converted to an ObjectId which is wrong. The document isn't found in this case because the spring data searches now for an oid:

findOne using query: { "_id" : { "$oid" : "151139921910640945084286"}} in db.collection: content.term

For all other string ids the query is correct:

findOne using query: { "_id" : "01200314690800000235"} in db.collection: content.term

The implementation leads to inconsistent behaviour in case of 24 digit string ids. IHMO there are two choices:

  1. fall back to the _id search if nothing is found for the $oid search
  2. add an additional annotation on the @Id field to make that behaviour explicit

My favour is option 2

Thanks,
Daniel


Affects: 2.1 RC2 (Lovelace), 2.0.10 (Kay SR10), 1.10.15 (Ingalls SR15)

Attachments:

Issue Links:

Referenced from: pull request #617, and commits 62dcda9, 6f8f7cd, 4c6f793, 5d39191, 74b9ea9, f88b161, b9bba63

4 votes, 6 watchers

Metadata

Metadata

Labels

in: coreIssues in core supportin: mappingMapping and conversion infrastructuretype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions