summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/cannot_rename_collection_to_system_collection.js
blob: 4be1738cf8faaf8f9f20681aa86c55175459f56d (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
/**
 * Verifies that we disallow renaming collections to system collections and vice-versa.
 */
(function() {
"use strict";

const dbName = "cannot_rename_collection_to_system_collection";

const testDB = db.getSiblingDB(dbName);

assert.commandFailedWithCode(testDB.createCollection("system.a"), ErrorCodes.InvalidNamespace);

testDB.getCollection("a").drop();
assert.commandWorked(testDB.createCollection("a"));

// Ensure we cannot rename "a" to a system collections
assert.commandFailedWithCode(testDB.getCollection("a").renameCollection("system.a"),
                             ErrorCodes.IllegalOperation);

// Ensure we cannot rename system collections to "a".
assert.commandFailedWithCode(
    db.getSiblingDB("admin").getCollection("system.version").renameCollection("a"),
    ErrorCodes.IllegalOperation);
}());