summaryrefslogtreecommitdiff
path: root/jstests/core/exists6.js
blob: 67ab7e5345db3087baf692aeeb469d93d6f1c5ef (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
// SERVER-393 Test indexed matching with $exists.

t = db.jstests_exists6;
t.drop();

t.ensureIndex({b: 1});
t.save({});
t.save({b: 1});
t.save({b: null});

assert.eq(2, t.find({b: {$exists: true}}).itcount());
assert.eq(2, t.find({b: {$not: {$exists: false}}}).itcount());
assert.eq(1, t.find({b: {$exists: false}}).itcount());
assert.eq(1, t.find({b: {$not: {$exists: true}}}).itcount());

// Now check existence of second compound field.
t.ensureIndex({a: 1, b: 1});
t.save({a: 1});
t.save({a: 1, b: 1});
t.save({a: 1, b: null});

assert.eq(2, t.find({a: 1, b: {$exists: true}}).itcount());
assert.eq(2, t.find({a: 1, b: {$not: {$exists: false}}}).itcount());
assert.eq(1, t.find({a: 1, b: {$exists: false}}).itcount());
assert.eq(1, t.find({a: 1, b: {$not: {$exists: true}}}).itcount());