summaryrefslogtreecommitdiff
path: root/jstests/core/explain_find.js
blob: a0578fd29c382f75de00b0f29ce3174a10828f1e (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
/**
 * Tests for explaining find through the explain command.
 * @tags: [
 *   assumes_read_concern_local,
 * ]
 */

(function() {
"use strict";

var collName = "jstests_explain_find";
var t = db[collName];
t.drop();

t.createIndex({a: 1});

for (var i = 0; i < 10; i++) {
    t.insert({_id: i, a: i});
}

var explain =
    db.runCommand({explain: {find: collName, filter: {a: {$lte: 2}}}, verbosity: "executionStats"});
assert.commandWorked(explain);
assert.eq(3, explain.executionStats.nReturned);

explain = db.runCommand({
    explain: {find: collName, min: {a: 4}, max: {a: 6}, hint: {a: 1}},
    verbosity: "executionStats",
});
assert.commandWorked(explain);
assert.eq(2, explain.executionStats.nReturned);

// Invalid verbosity string.
let error = assert.throws(function() {
    t.explain("foobar").find().finish();
});
assert.commandFailedWithCode(error, ErrorCodes.BadValue);

error = assert.throws(function() {
    t.find().explain("foobar");
});
assert.commandFailedWithCode(error, ErrorCodes.BadValue);
}());