summaryrefslogtreecommitdiff
path: root/jstests/core/explain_missing_collection.js
blob: 458b15c6a8059e67431f3a65110f81cf13e96fbf (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Cannot implicitly shard accessed collections because of unsupported group operator on sharded
// collection.
// @tags: [assumes_unsharded_collection]

// Test explain of various operations against a non-existent collection
(function() {
    var missingColl = db.explain_null_collection;

    var explain;
    var explainColl;

    // .find()
    missingColl.drop();
    explain = missingColl.explain("executionStats").find().finish();
    assert.commandWorked(explain);
    assert("executionStats" in explain);

    // .count()
    missingColl.drop();
    explain = missingColl.explain("executionStats").count();
    assert.commandWorked(explain);
    assert("executionStats" in explain);

    // .group()
    missingColl.drop();
    explainColl = missingColl.explain("executionStats");
    explain = explainColl.group({key: "a", initial: {}, reduce: function() {}});
    assert.commandWorked(explain);
    assert("executionStats" in explain);

    // .remove()
    missingColl.drop();
    explain = missingColl.explain("executionStats").remove({a: 1});
    assert.commandWorked(explain);
    assert("executionStats" in explain);

    // .update() with upsert: false
    missingColl.drop();
    explainColl = missingColl.explain("executionStats");
    explain = explainColl.update({a: 1}, {b: 1});
    assert.commandWorked(explain);
    assert("executionStats" in explain);

    // .update() with upsert: true
    missingColl.drop();
    explainColl = missingColl.explain("executionStats");
    explain = explainColl.update({a: 1}, {b: 1}, {upsert: true});
    assert.commandWorked(explain);
    assert("executionStats" in explain);

    // .aggregate()
    missingColl.drop();
    explain = missingColl.explain("executionStats").aggregate([{$match: {a: 1}}]);
    assert.commandWorked(explain);
}());