7

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
  • 1
    I think the $ symbol in your query is not needed Commented Mar 10, 2013 at 14:47

1 Answer 1

12

Your $pull syntax is off, it should be:

db.tt.update({'comments.name': '2'}, {$pull: {comments: {name: '2'}}})
Sign up to request clarification or add additional context in comments.

3 Comments

db.col.find() { "_id" : ObjectId("d53d7810352eaec7c154b711"), "name" : "Amount", "type" : "text", "message" : { "test value" : 1, "test value1" : 6 } } db.col.update({"_id":ObjectId("d53d7810352eaec7c154b711")},{$pull :{"message": {"test value" : 1}}}); i tried this it is not working for me
@RaviKumar Please post that as a new question if you're still having trouble.
With what this "{$pull: {comments: {name: '2'}}}" can be replaced,to make it accept string as question poster was trying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.