|
Yes, this can documented (better).
In the upcoming release your $and example works, and there should be no corner case there anymore:
> db.fun.update({$and:[{B:1263},{G:1234}]},{$inc:{A:100}},{multi:true,upsert:true});
|
Update WriteResult({ "ok" : 1, "n" : 1, "upserted" : ObjectId("528e01c48413745829bec3b4") })
|
> db.fun.find()
|
{ "_id" : ObjectId("528e01c48413745829bec3b4"), "B" : 1263, "G" : 1234, "A" : 100 }
|
In the future this should be less confusing since it works with $and, and nested $and conditions.
|
|
Sorry, the $or operator was a bad example, i'll give you an example for the $and operator
This query :
db.fun.update({$and:[{B:1263},{G:1234}]},{$inc:{A:100}},{multi:true,upsert:true});
|
insert this document :
{ "_id" : ObjectId("528dba9ce91666571f2af0f6"), "A" : 100 }
|
but what i was waiting for
{ "_id" : ObjectId("528dbb43e91666571f2af0f7"), "A" : 100, "B" : 1263, "G" : 1234 }
|
to be inserted,as the update query above is the same as this one :
db.fun.update({B:1263,G:1234},{$inc:{A:100}},{multi:true,upsert:true});
|
When you use the $or, things are less clear; but when i made this query
db.truc.update({$or:[{B:1263},{G:1234}]},{$inc:{A:100}},{multi:true,upsert:true});
|
i thought that no document will be inserted ( like, for example :
db.fun.update({G:{$gt:1442}},{$inc:{A:100}},{multi:true,upsert:true});
|
)
i know that upset should be used with "simple" query
{<field>:<value>}
, and that the case above are kind of edge case that you'll rarely encounter, but i think that these behaviour could be documented.
|