...
When I use $pull to remove some DBRef using $id and $in operator, none of them are remove. If the $id field have another name works.
asya commented on Fri, 28 Nov 2014 14:39:59 +0000: That case should not work - I believe that may be a bug. I will check why this case works contrary to documentation. gabrielbrieva commented on Fri, 28 Nov 2014 13:37:10 +0000: But in this case works: Two documents: { "foo" : "test1", "rel" : [ { "t" : "t", "id" : 2 } , { "t" : "t", "id" : 3 } ] } { "foo" : "test2", "rel" : [ { "t" : "t", "id" : 2 } , { "t" : "t", "id" : 1 } ] } The query: db.test.update({}, {"$pull": { "rel": { "id": { "$in": [1, 3] } } } }, {"multi": true} ) That query remove {"t" : "t", "id" : 1} and {"t" : "t", "id" : 3} from documents. So, why don't works for DBRef case? asya commented on Fri, 28 Nov 2014 09:41:58 +0000: The result you're getting is correct. Documentation for $pull specifies a number of behaviors: http://docs.mongodb.org/manual/reference/operator/update/pull/#up._S_pull Note it says: If the specified to remove is a document, $pull removes only the elements in the array that have the exact same fields and values. You are asking to pull by trying to match document where "rel" has the value {"$id": ...} which is not the object that "rel" has. What will work is: db.test.update({},{"$pull":{"rel": { "$in": [{"$ref":"bar","$id": ObjectId("54773af88328753e92484be8")}, {"$ref":"bar","$id":ObjectId("5477954518c7885d7651a15a")} ] } }})
I have this two documents: { foo : "test2", rel : [ { $ref : "bar", $id : ObjectId("54773af88328753e92484be8") } , { $ref : "bar", $id : ObjectId("54480b5f18c7885d7651a140") } ] } { foo : "test2", rel : [ { $ref : "bar", $id : ObjectId("54480b5f18c7885d7651a140") } , { $ref : "bar", $id : ObjectId("54773af88328753e92484be8") } ] } When I use $pull to remove some of DBRef entries and using $in too, none of them are removed. This is the query: db.test.update({}, {$pull: { rel: { "$id": { $in: [ ObjectId("54773af88328753e92484be8"), ObjectId("5477954518c7885d7651a15a") ] } } } })