2010-03-16 14:05:41 -07:00
|
|
|
let t = db.jstests_pullall;
|
2009-07-21 18:37:30 -04:00
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [1, 2, 3]});
|
|
|
|
|
t.update({}, {$pullAll: {a: [3]}});
|
|
|
|
|
assert.eq([1, 2], t.findOne().a);
|
|
|
|
|
t.update({}, {$pullAll: {a: [3]}});
|
|
|
|
|
assert.eq([1, 2], t.findOne().a);
|
2009-07-21 18:37:30 -04:00
|
|
|
|
|
|
|
|
t.drop();
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [1, 2, 3]});
|
|
|
|
|
t.update({}, {$pullAll: {a: [2, 3]}});
|
|
|
|
|
assert.eq([1], t.findOne().a);
|
|
|
|
|
t.update({}, {$pullAll: {a: []}});
|
|
|
|
|
assert.eq([1], t.findOne().a);
|
|
|
|
|
t.update({}, {$pullAll: {a: [1, 5]}});
|
|
|
|
|
assert.eq([], t.findOne().a);
|
2009-07-21 18:37:30 -04:00
|
|
|
|
2012-07-02 15:12:34 -04:00
|
|
|
// SERVER-6047: $pullAll creates empty nested docs for dotted fields
|
|
|
|
|
// that don't exist.
|
2016-02-04 12:29:01 -05:00
|
|
|
t.drop();
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({m: 1});
|
2025-08-21 10:17:44 -07:00
|
|
|
t.update({m: 1}, {$pullAll: {"a.b": [1]}});
|
|
|
|
|
assert("a" in t.findOne() == false);
|
2012-07-02 15:12:34 -04:00
|
|
|
// Non-obvious bit: the implementation of non-in-place update
|
|
|
|
|
// might do different things depending on whether the "new" field
|
|
|
|
|
// comes before or after existing fields in the document.
|
|
|
|
|
// So for now it's worth testing that too. Sorry, future; blame the past.
|
2025-08-21 10:17:44 -07:00
|
|
|
t.update({m: 1}, {$pullAll: {"x.y": [1]}});
|
|
|
|
|
assert("z" in t.findOne() == false);
|
2012-07-02 15:12:34 -04:00
|
|
|
// End SERVER-6047
|