[SERVER-6213] Failed to apply an update with multiple conditions in an array Created: 26/Jun/12  Updated: 15/Aug/12  Resolved: 26/Jun/12

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

Type: Bug Priority: Major - P3
Reporter: Kijam Lopez Assignee: Daniel Crosta
Resolution: Duplicate Votes: 0
Labels: query, update
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb-linux-i686-2.0.4
Fedora 2.6.42.3-2.fc15.i686


Operating System: ALL
Participants:

 Description   

db.bug.save({
_id:1,
test:[

{cid:1, cond:100, weight:5}

,

{cid:2, cond:200, weight:5}

,

{cid:3, cond:300, weight:5}

,

{cid:4, cond:400, weight:5}

]
});
db.bug.find().pretty();
{
"_id" : 1,
"test" : [

{ "cid" : 1, "cond" : 100, "weight" : 5 }

,

{ "cid" : 2, "cond" : 200, "weight" : 5 }

,

{ "cid" : 3, "cond" : 300, "weight" : 5 }

,

{ "cid" : 4, "cond" : 400, "weight" : 5 }

]
}

db.bug.update(

{"test.cid":3}

, {$inc:{"test.$.weight":1}});
db.bug.find().pretty();
{
"_id" : 1,
"test" : [

{ "cid" : 1, "cond" : 100, "weight" : 5 }

,

{ "cid" : 2, "cond" : 200, "weight" : 5 }

,

{ "cid" : 3, //<< Satisfies the condition! ("test.cid":3)... "cond" : 300, "weight" : 6 //<< The increase is correct!... }

,

{ "cid" : 4, "cond" : 400, "weight" : 5 }

]
}

db.bug.update({"test.cid":3, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}});
db.bug.find().pretty()
{
"_id" : 1,
"test" : [

{ "cid" : 1, "cond" : 100, "weight" : 5 }

,
{
"cid" : 2, //<< Not satisfy condition! ("test.cid":3)...
"cond" : 200, //<< Satisfies the condition! ("test.cond": {$gt:150})...
"weight" : 6 //<< Increase is this correct?...
},
{
"cid" : 3, //<< Satisfies the condition! ("test.cid":3)...
"cond" : 300, //<< Satisfies the condition! ("test.cond": {$gt:150})...
"weight" : 6 //<< No increase
},

{ "cid" : 4, "cond" : 400, "weight" : 5 }

]
}

db.bug.update({"test.cid":1, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}});
db.bug.find().pretty()
{
"_id" : 1,
"test" : [
{
"cid" : 1, //<< Not satisfy condition! ("test.cid":1)...
"cond" : 100, //<< No Match condition ("test.cond": {$gt:150})...
"weight" : 5 //<< No increase
},
{
"cid" : 2, //<< Not satisfy condition! ("test.cid":1)...
"cond" : 200, //<< Satisfies the condition! ("test.cond": {$gt:150})...
"weight" : 7 //<< Increase is this correct?...
},

{ "cid" : 3, "cond" : 300, "weight" : 6 }

,

{ "cid" : 4, "cond" : 400, "weight" : 5 }

]
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 26/Jun/12 ]

Dup of SERVER-6212

Comment by Kijam Lopez [ 26/Jun/12 ]

FIX:
db.bug.update({"test.cid":1, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}});
db.bug.find().pretty()
{
"_id" : 1,
"test" : [
{
"cid" : 1, //<< Satisfies the condition! ("test.cid":1)...
"cond" : 100, //<< Not satisfy condition! ("test.cond": {$gt:150})...
"weight" : 5 //<< No increase
},
{
"cid" : 2, //<< Not satisfy condition! ("test.cid":1)...
"cond" : 200, //<< Satisfies the condition! ("test.cond": {$gt:150})...
"weight" : 7 //<< Increase is this correct?...
},

{ "cid" : 3, "cond" : 300, "weight" : 6 }

,

{ "cid" : 4, "cond" : 400, "weight" : 5 }

]
}

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