Deleting object in child collection in MongoDB
I have a collection of content. This collection has a set of answers as such
Content : [{ 'id' : '1234',
'Responses' : [{
'id' : '12345'
}
etc .. Now I want to delete answer 12345, but I don't want to delete all answers. I can't seem to find a command for this. I am under the impression that the correct action is to grab the object, restore responses without the one I want to delete, and then store the Content object as a whole. Given that there are many answers, it seems like bad practice to load the entire object this way.
+2
a source to share
1 answer
$pull
is what you are looking for. See documentation for details:
http://www.mongodb.org/display/DOCS/Updating#Updating-%24pull
+1
a source to share