MongoDb: Query not pulling item from array - why? -


the intention of query below pull items locs array, x=2 , y=9. items these values remain in array after query.

 db.mycollection.update(        { }, //all records        { $pull: { 'locs' : { $elemmatch : {'x' : 2 , 'y' : 9 } } } }  ) 

could tell me why it's not working?

edit: example document:

{   "_id" : objectid("55555555555"),   "locs" : [{       "x" : 2,       "y" : 9     }],   "v" : 99 } 

in general, $pull not work this. removes "a value array" (http://docs.mongodb.org/manual/reference/operator/pull/). can not use $elemmatch here, neither have to.

so if have document looks this:

{     'title': 'example',     'locs': [         { x: 2, y: 12 },         { x: 7, y: 9 },         { x: 2, y: 9 },     ] } 

the follow should remove x:2 / y:9 value pair:

db.so.update(     {},     { $pull: { 'locs' : { 'x' : 2 , 'y' : 9 } } } ); 

which has:

{     'title': 'example',     'locs': [         { x: 2, y: 12 },         { x: 7, y: 9 },     ] } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -