-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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:
- fall back to the _id search if nothing is found for the $oid search
- add an additional annotation on the
@Idfield 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:
- com.sap.content.tag.zip (19.96 kB)
Issue Links:
-
DATAMONGO-2202 Document how to insert _id field as String and not ObjectId
-
DATAMONGO-1988 String ID not working for embeded objects
-
DATAMONGO-879 Create
@ObjectIdAnnotation
("supersedes")
Referenced from: pull request #617, and commits 62dcda9, 6f8f7cd, 4c6f793, 5d39191, 74b9ea9, f88b161, b9bba63
4 votes, 6 watchers