Skip to content
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

Pull command dropping other changes to sub document arrays depending on their order #1303

Closed
mseegers opened this issue Jan 19, 2013 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.

Comments

@mseegers
Copy link

Hi,

I've been running into an issue where a change to one sub document gets dropped when also pulling another sub document depending on the order that these two changes are made. Please see the following minimal reproduction code:

https://gist.github.com/4575777

The debug output for both order cases is as follows.

Correct case saving the following:

var mySub = doc.subDocs[2];
doc.subDocs.pull(doc.subDocs[1]);
mySub.someValue = 5;

results in

Mongoose: docs.update({ _id: ObjectId("50fb28517c9e6e9c8a000002"), __v: 0 }) { '$inc': { __v: 1 }, '$set': { subDocs: [ { _id: ObjectId("50fb28517c9e6e9c8a000005"), someValue: 1 }, { _id: ObjectId("50fb28517c9e6e9c8a000003"), someValue: 5 } ] } } {} 

Incorrect case saving the following:

var mySub = doc.subDocs[2];
mySub.someValue = 5;
doc.subDocs.pull(doc.subDocs[1]);

results in

Mongoose: docs.update({ _id: ObjectId("50fb2973817ac5b18a000002"), __v: 0 }) { '$inc': { __v: 1 }, '$pull': { subDocs: { _id: { '$in': [ ObjectId("50fb2973817ac5b18a000004") ] } } } } {}

I would greatly appreciate any help with this. Please let me know if I am overlooking something. Thanks!

This is using mongoose 3.5.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants