summaryrefslogtreecommitdiff
path: root/jstests/cqf/object_elemMatch.js
blob: e1baf046e9b930a0618ae86f3a39c0e447afe921 (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
35
36
37
38
(function() {
"use strict";

load("jstests/libs/optimizer_utils.js");  // For checkCascadesOptimizerEnabled.
if (!checkCascadesOptimizerEnabled(db)) {
    jsTestLog("Skipping test because the optimizer is not enabled");
    return;
}

const t = db.cqf_object_elemMatch;

t.drop();
assert.commandWorked(t.insert({a: [{a: 1, b: 1}, {a: 1, b: 2}]}));
assert.commandWorked(t.insert({a: [{a: 2, b: 1}, {a: 2, b: 2}]}));
assert.commandWorked(t.insert({a: {a: 2, b: 1}}));
assert.commandWorked(t.insert({a: [{b: [1, 2], c: [3, 4]}]}));
assert.commandWorked(t.insert({a: [{"": [1, 2], c: [3, 4]}]}));

{
    // Object elemMatch. Currently we do not support index here.
    const res = t.explain("executionStats").aggregate([{$match: {a: {$elemMatch: {a: 2, b: 1}}}}]);
    assert.eq(1, res.executionStats.nReturned);
    assertValueOnPlanPath("PhysicalScan", res, "child.child.child.nodeType");
}

{
    // Should not be getting any results.
    const res = t.explain("executionStats").aggregate([
        {$match: {a: {$elemMatch: {b: {$elemMatch: {}}, c: {$elemMatch: {}}}}}}
    ]);
    assert.eq(0, res.executionStats.nReturned);
}
{
    const res = t.explain("executionStats").aggregate([{$match: {a: {$elemMatch: {"": 1}}}}]);
    assert.eq(1, res.executionStats.nReturned);
    assertValueOnPlanPath("PhysicalScan", res, "child.child.child.nodeType");
}
}());