summaryrefslogtreecommitdiff
path: root/jstests/core/system_js_drop.js
blob: 49a59c14ed53fe2c660416e7b803c40c901a272c (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
/**
 * Tests dropping the system.js collection.
 *
 * @tags: [
 *   assumes_read_preference_unchanged,
 *   assumes_unsharded_collection,
 *   requires_fcv_62,
 *   requires_non_retryable_writes,
 * ]
 */
(function() {
'use strict';

const testDB = db.getSiblingDB(jsTestName());
assert.commandWorked(testDB.dropDatabase());

const coll = testDB.coll;
const systemJs = testDB.system.js;

assert.commandWorked(coll.insert([{name: 'Alice', age: 20}, {name: 'Bob', age: 18}]));

assert.commandWorked(systemJs.insert({
    _id: "isTeenager",
    value: function(age) {
        return age >= 13 && age <= 19;
    },
}));

assert.commandWorked(
    testDB.runCommand({find: coll.getName(), filter: {$where: "isTeenager(this.age)"}}));

assert(systemJs.drop());

assert.commandFailedWithCode(
    testDB.runCommand({find: coll.getName(), filter: {$where: "isTeenager(this.age)"}}),
    ErrorCodes.JSInterpreterFailure);
})();