2016-02-04 12:29:01 -05:00
|
|
|
let t = db.update_arraymatch1;
|
2010-03-06 22:12:58 -05:00
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
let o = {_id: 1, a: [{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}]};
|
|
|
|
|
t.insert(o);
|
|
|
|
|
assert.eq(o, t.findOne(), "A1");
|
2010-03-06 22:12:58 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
let q = {"a.x": 2};
|
|
|
|
|
t.update(q, {$set: {b: 5}});
|
2016-02-04 12:29:01 -05:00
|
|
|
o.b = 5;
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(o, t.findOne(), "A2");
|
2010-03-06 22:12:58 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.update({"a.x": 2}, {$inc: {"a.$.y": 1}});
|
2010-03-06 22:12:58 -05:00
|
|
|
o.a[1].y++;
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(o, t.findOne(), "A3");
|