mongodb - Remove embedded document in a nested array of documents -
my schema looks this:
"content" : [ { "_id" : objectid("4fc63de85b20fb72290000f8"), "assets" : [ { "path" : "temp/4f840af9565832fa14000002/4f840b1e565832fa14000007/4fc63de85b20fb72290000f7/content/i_understanding_and_measuring.pdf", "_id" : objectid("4fc63def5b20fb722900010e") }, { "path" : "temp/4f840af9565832fa14000002/4f840b1e565832fa14000007/4fc63de85b20fb72290000f7/content/me.jpg", "_id" : objectid("4fc63e4d5b20fb722900015d") } ], "content" : "", "name" : "downloads" }, { "_id" : objectid("4fc63dfd5b20fb722900012a"), "assets" : [ { "path" : "temp/4f840af9565832fa14000002/4f840b1e565832fa14000007/4fc63de85b20fb72290000f7/content/me.jpg", "_id" : objectid("4fc63e055b20fb7229000147") }, { "path" : "temp/4f840af9565832fa14000002/4f840b1e565832fa14000007/4fc63de85b20fb72290000f7/content/thierry-henry-12-31-11-1.jpg", "_id" : objectid("4fc63e525b20fb7229000164") } ], "content" : "", "name" : "bio" } ],
i can retrieve document with:
db.presentations.find({'content.assets._id': objectid('4fc63def5b20fb722900010e')})`
i've tried following remove document assets collection line below, no avail:
db.presentations.update( {'content.assets._id': objectid('4fc63def5b20fb722900010e')}, {$pull: {'content.assets': {'_id': objectid('4fc63def5b20fb722900010e')}}} )
i'm trying remove item corresponding assets
collection id. ideas?
you close! remember outermost "content" array itself. following 2 character change works, use content.$.assets inside value $pull.
db.presentations.update( {'content.assets._id': objectid('4fc63def5b20fb722900010e')}, {$pull: {'content.$.assets': {'_id': objectid('4fc63def5b20fb722900010e')}}} )
zoom ahead.
Comments
Post a Comment