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

Unable to $pull from single sub-document which containes array of objects #3616

Closed
tmfelwu opened this issue Nov 25, 2015 · 4 comments
Closed
Milestone

Comments

@tmfelwu
Copy link

tmfelwu commented Nov 25, 2015

$pull from a single subdocument fails

var ParentSchema = new Schema({
  child: childSchema
})

var ChildSchema = new Schema({
items:[itemsSchema]
})

the below query fails to pull from items array

Parent.findOneAndUpdate(query, {$pull:{'child.tems':{_id: itemID}}})

whereas the following works on mongodb

db.parent.update(query, {$pull:{'child.tems':{_id: itemID}}})
@vkarpov15
Copy link
Collaborator

Are you sure the issue isn't due to the fact that you typoed on 'items' in your findOneAndUpdate call?

@tmfelwu
Copy link
Author

tmfelwu commented Nov 27, 2015

Yes definitely not due to the typo here. Now i am using embedded document instead of defining a subdocument that works fine.

@vkarpov15 vkarpov15 added this to the 4.2.9 milestone Nov 28, 2015
vkarpov15 added a commit that referenced this issue Nov 28, 2015
@tmfelwu
Copy link
Author

tmfelwu commented Nov 29, 2015

@vkarpov15 can you tell if there is any difference between using subdocument and embedded document, apart from using subdocument assigns a _id field where as embedded document doesnt.

Any advantage of one over the other?

@vkarpov15
Copy link
Collaborator

In theory they should have the same semantics. Can you show me some code that reproduces the _id issue you mentioned? That shouldn't happen either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants