summaryrefslogtreecommitdiff
path: root/jstests/core/unset.js
blob: 14e18229723fd93e1e2b9adeebad81c4bbf25313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
t = db.unset;
t.drop();

orig = {
    _id: 1,
    emb: {}
};
t.insert(orig);

t.update({_id: 1}, {$unset: {'emb.a': 1}});
t.update({_id: 1}, {$unset: {'z': 1}});
assert.eq(orig, t.findOne(), "A");

t.update({_id: 1}, {$set: {'emb.a': 1}});
t.update({_id: 1}, {$set: {'z': 1}});

t.update({_id: 1}, {$unset: {'emb.a': 1}});
t.update({_id: 1}, {$unset: {'z': 1}});
assert.eq(orig, t.findOne(), "B");  // note that emb isn't removed

t.update({_id: 1}, {$unset: {'emb': 1}});
assert.eq({_id: 1}, t.findOne(), "C");