-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Inconsistent _id
Storage Type Between save
and saveAll
for @MongoId String id
#4944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
thanks for reporting - we'll look into it |
christophstrobl
added a commit
that referenced
this issue
Apr 11, 2025
This commit fixes an issue where id properties annotated with MongoId had not been converted into the desired target type when inserting a collection of objects instead a single one. Resolves: #4944
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
When using Spring Data MongoDB with entities annotated with
@MongoId String id
, there is an inconsistency in how the_id
field is stored in MongoDB depending on whethersave
orsaveAll
is used. Specifically,save
stores the_id
as aString
, whilesaveAll
stores it as anObjectId
, even though the ID is not explicitly set in either case.That even leads to duplication in the DB, since when used
saveAll
and theupdate
it will convert it to string but creates a duplicated objectSteps to Reproduce
Expected Behavior
save
andsaveAll
store_id
as a String in MongoDB whenid
isnull
and the field isString
.Actual Behavior
save
stores_id
as aString
.saveAll
stores _id as anObjectId
.saveAll
creates a duplicate due to the type mismatch.Environment
Test Project To Reproduce
mongo-bug.zip
The text was updated successfully, but these errors were encountered: