[SERVER-11791] Insert from update (w/upsert:true) ignores $and equality fields Created: 20/Nov/13  Updated: 09/Jul/16  Resolved: 04/Dec/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Chabbey François Assignee: Scott Hernandez (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-11389 Use CanonicalQuery to return equality... Closed
Operating System: ALL
Participants:

 Description   

Example :

db.truc.update({$or:[{B:1263},{G:1234}]},{$inc:{A:100}},{multi:true,upsert:true});
 
inserts this document : 
{ "_id" : ObjectId("528cd977e91666571f2af0f1"), "A" : 100 }

Is it a desired behaviour, if yes , is it documented somewhere ?

Thanks



 Comments   
Comment by Scott Hernandez (Inactive) [ 21/Nov/13 ]

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.

Comment by Chabbey François [ 21/Nov/13 ]

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.

Comment by Scott Hernandez (Inactive) [ 20/Nov/13 ]

Can you be a little more clear which part is strange, and why you feel that way? If you feel like there should be a different result from the update, what would it be?

Generated at Thu Feb 08 03:26:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.