summaryrefslogtreecommitdiff
path: root/jstests/core/explain_uuid.js
blob: 4f61479976350aa4cbac5f5ab2473c18a504f8d8 (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
56
57
58
/**
 * Test that running explain() providing a collection UUID rather than collection name will fail
 * cleanly.
 * @tags: [
 *   no_selinux,
 * ]
 */
(function() {
"use strict";

// Use our own database so that we're guaranteed the only collection is this one.
const explainDB = db.getSiblingDB("explain_uuid_db");

assert.commandWorked(explainDB.dropDatabase());

const coll = explainDB.explain_uuid;
assert.commandWorked(coll.insert({a: 1}));

const collInfos = explainDB.getCollectionInfos({name: coll.getName()});
assert.eq(collInfos.length, 1, collInfos);
const uuid = collInfos[0].info.uuid;

// Run a find explain looking up by UUID.
assert.commandFailedWithCode(explainDB.runCommand({explain: {find: uuid}}),
                             ErrorCodes.InvalidNamespace);

// Do similar for other commands.
assert.commandFailedWithCode(explainDB.runCommand({explain: {aggregate: uuid, cursor: {}}}),
                             ErrorCodes.TypeMismatch);

assert.commandFailedWithCode(explainDB.runCommand({explain: {count: uuid}}),
                             ErrorCodes.InvalidNamespace);

assert.commandFailedWithCode(explainDB.runCommand({explain: {distinct: uuid, key: "x"}}),
                             ErrorCodes.InvalidNamespace);

// When auth is enabled, running findAndModify with an invalid namespace will produce a special
// error during the auth check, rather than the generic 'InvalidNamespace' error.
const expectedCode = TestData.auth ? 17137 : ErrorCodes.InvalidNamespace;
assert.commandFailedWithCode(
    explainDB.runCommand({explain: {findAndModify: uuid, query: {a: 1}, remove: true}}),
    [expectedCode, ErrorCodes.BadValue]);

assert.commandFailedWithCode(
    explainDB.runCommand({explain: {delete: uuid, deletes: [{q: {}, limit: 1}]}}),
    ErrorCodes.BadValue);

assert.commandFailedWithCode(explainDB.runCommand({
    explain: {
        update: uuid,
        updates: [{
            q: {a: 1},
            u: {$set: {b: 1}},
        }]
    }
}),
                             ErrorCodes.BadValue);
})();