summaryrefslogtreecommitdiff
path: root/jstests/core/expr_or_pushdown.js
blob: e2605e08c9109df950eae75807a2e089fca17857 (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
/**
 * Test that an $expr predicated which is eligible for being indexed with an $or pushdown executes
 * as expected.
 */
(function() {
"use strict";

const coll = db.expr_or_pushdown;
coll.drop();
assert.commandWorked(coll.createIndex({"a": 1, "b": 1}));
assert.commandWorked(coll.insert({_id: 0, a: "a", b: "b", d: "d"}));
assert.commandWorked(coll.insert({_id: 1, a: "a", b: "c", d: "d"}));
assert.commandWorked(coll.insert({_id: 2, a: "a", b: "x", d: "d"}));
assert.commandWorked(coll.insert({_id: 3, a: "x", b: "b", d: "d"}));
assert.commandWorked(coll.insert({_id: 4, a: "a", b: "b", d: "x"}));

const results = coll.find({
                        $expr: {$and: [{$eq: ["$d", "d"]}, {$eq: ["$a", "a"]}]},
                        $or: [{"b": "b"}, {"b": "c"}]
                    })
                    .sort({_id: 1})
                    .toArray();

assert.eq(results, [{_id: 0, a: "a", b: "b", d: "d"}, {_id: 1, a: "a", b: "c", d: "d"}]);
}());