summaryrefslogtreecommitdiff
path: root/jstests/core/remove_undefined.js
blob: af7dce1e40947c1466d7f122cba41099bc947094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function() {
    "use strict";

    const coll = db.remove_undefined;
    coll.drop();

    assert.writeOK(coll.insert({_id: 1}));
    assert.writeOK(coll.insert({_id: 2}));
    assert.writeOK(coll.insert({_id: null}));

    const obj = {foo: 1, nullElem: null};

    coll.remove({x: obj.bar});
    assert.eq(3, coll.count());

    coll.remove({x: undefined});
    assert.eq(3, coll.count());

    assert.writeErrorWithCode(coll.remove({_id: obj.bar}), ErrorCodes.BadValue);
    assert.writeErrorWithCode(coll.remove({_id: undefined}), ErrorCodes.BadValue);

    coll.remove({_id: obj.nullElem});
    assert.eq(2, coll.count());

    assert.writeOK(coll.insert({_id: null}));
    assert.eq(3, coll.count());

    assert.writeErrorWithCode(coll.remove({_id: undefined}), ErrorCodes.BadValue);
    assert.eq(3, coll.count());
})();