[SERVER-6212] Failed to apply an update with multiple conditions in an array Created: 26/Jun/12 Updated: 09/Jul/16 Resolved: 26/Jun/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying, Write Ops |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kijam Lopez | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | query, update | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
db.bug.save({ , , , {cid:4, cond:400, weight:5} ] , , , { "cid" : 4, "cond" : 400, "weight" : 5 } ] db.bug.update( {"test.cid":3}, {$inc:{"test.$.weight":1}}); , , , { "cid" : 4, "cond" : 400, "weight" : 5 } ] db.bug.update({"test.cid":3, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}}); , ] db.bug.update({"test.cid":1, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}}); , { "cid" : 4, "cond" : 400, "weight" : 5 } ] |
| Comments |
| Comment by Scott Hernandez (Inactive) [ 26/Jun/12 ] |
|
Use $elemMatch as your current query only requires the document meet those conditions, not any single array element. http://www.mongodb.org/display/DOCS/Advanced%20Queries#AdvancedQueries-%24elemMatch |