summaryrefslogtreecommitdiff
path: root/jstests/core/query/exists/exists6.js
blob: 736574db8953d576752a153269876a55dfbc5401 (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.createIndex({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.createIndex({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());