-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Shuffling composite _id key issue #4542
Milestone
Comments
Good catch! Will fix this for next release |
So looking into this, this is actually a very difficult problem tied into #2749, my least favorite legacy mongoose feature. Fixing is gonna take another week or two, thanks for your patience 🍻 🌴 |
vkarpov15
added a commit
that referenced
this issue
Oct 16, 2016
vkarpov15
added a commit
that referenced
this issue
Oct 16, 2016
Merged
vkarpov15
added a commit
that referenced
this issue
Oct 17, 2016
tusbar
added a commit
to IONISx/edx-modulestore-node
that referenced
this issue
Oct 25, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Issue : When I'm saving an object with a composite _id, update will be silently ignored.
Proof of the issue :
Investigating :
Sorting of keys in the ID is not insured, so {key1, key2} will find the doc, but {key2,key1} will match with 0 docs.
When Mongoose call update, (btw, update is deprecated now, please replace by updateOne) where may be with the bad order for keys.
On the FindOne, _id object may be shuffled. So, on update, bad sorted _id may be embed into the updateOne, so the save() will fail. (Return 0 documents modified, but no error throwed).
Workaround :
I'm using a workaround, but with a potential performance issue (not benchmarked), I've overrided the Model of mongoose, to decompose _id key.
{_id: {key1, key2}}
will become{"_id.key1", "_id.key2"}
With this syntax, order is not important.To override model, please see PR #4541, then you can do something like that (findById overrided too, for example) :
Have a nice day,
Gaël
The text was updated successfully, but these errors were encountered: