summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/disallow_system_views_rename.js
blob: c9bc901041e3dda20e00237eac31a4cd75412df5 (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
(function() {
'use strict';
assert.commandWorked(db.runCommand({insert: 'a', documents: [{x: 1}]}));

// Disallow renaming to system.views
assert.commandFailedWithCode(db.adminCommand({renameCollection: 'test.a', to: 'test.system.views'}),
                             ErrorCodes.IllegalOperation);

assert.commandWorked(db.createView('viewA', 'a', []));

// Disallow renaming from system.views
assert.commandFailedWithCode(
    db.adminCommand({renameCollection: 'test.system.views', to: 'test.aaabb'}),
    ErrorCodes.IllegalOperation);

// User can still rename system.views (or to system.views) via applyOps command.
assert.commandWorked(db.adminCommand({
    applyOps: [{op: 'c', ns: 'test.$cmd', o: {renameCollection: 'test.system.views', to: 'test.b'}}]
}));

assert.commandWorked(db.adminCommand({
    applyOps: [{op: 'c', ns: 'test.$cmd', o: {renameCollection: 'test.b', to: 'test.system.views'}}]
}));
})();