summaryrefslogtreecommitdiff
path: root/jstests/core/arrayfind9.js
blob: 5406ae8c1d1d33f6ddebecf72425bc8639eea66c (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
31
32
33
34
// Assorted $elemMatch behavior checks.

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

// Top level field $elemMatch:$not matching
t.save({a: [1]});
assert.eq(1, t.count({a: {$elemMatch: {$not: {$ne: 1}}}}));

// Top level field object $elemMatch matching.
t.drop();
t.save({a: [{}]});
assert.eq(1, t.count({a: {$elemMatch: {$gte: {}}}}));

// Top level field array $elemMatch matching.
t.drop();
t.save({a: [[]]});
assert.eq(1, t.count({a: {$elemMatch: {$in: [[]]}}}));

// Matching by array index.
t.drop();
t.save({a: [['x']]});
assert.eq(1, t.count({a: {$elemMatch: {'0': 'x'}}}));

// Matching multiple values of a nested array.
t.drop();
t.save({a: [{b: [0, 2]}]});
t.createIndex({a: 1});
t.createIndex({'a.b': 1});
plans = [{$natural: 1}, {a: 1}, {'a.b': 1}];
for (i in plans) {
    p = plans[i];
    assert.eq(1, t.find({a: {$elemMatch: {b: {$gte: 1, $lte: 1}}}}).hint(p).itcount());
}