mongodb Cannot apply $pull/$pullAll modifier to no

2020-07-14 03:48发布

问题:

i met a problem about mongodb.

db.tt.find()
{ "_id" : ObjectId("513c971be4b1f9d71bc8c769"), 
  "name" : "a", 
  "comments" : [ { "name" : "2" }, { "name" : "3" } ] 
}

above is a test document.

i want to pull comments.name = 2

i do

db.tt.update({'comments.name':'2'},{'$pull':{'comments.$.name':'2'}});

but the console print these message:

Cannot apply $pull/$pullAll modifier to non-array

my mongodb version is 2.0.6

who can help me? Thank you very much

回答1:

Your $pull syntax is off, it should be:

db.tt.update({'comments.name': '2'}, {$pull: {comments: {name: '2'}}})


标签: mongodb