summaryrefslogtreecommitdiff
path: root/jstests/core/rename_collection_staytemp.js
blob: 594169d65e1254033e688f688e6b373d919d3a7f (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
/*
 * @tags: [
 *   requires_non_retryable_commands,
 *   requires_replication,
 *   # applyOps is not supported on mongos
 *   assumes_unsharded_collection,
 *   assumes_against_mongod_not_mongos,
 *   # Tenant migrations don't support applyOps.
 *   tenant_migration_incompatible,
 * ]
 */

orig = 'rename_stayTemp_orig';
dest = 'rename_stayTemp_dest';

db[orig].drop();
db[dest].drop();

function ns(coll) {
    return db[coll].getFullName();
}

function istemp(name) {
    var result = db.runCommand("listCollections", {filter: {name: name}});
    assert(result.ok);
    var collections = new DBCommandCursor(db, result).toArray();
    assert.eq(1, collections.length);
    return collections[0].options.temp ? true : false;
}

assert.commandWorked(
    db.runCommand({applyOps: [{op: "c", ns: db.getName() + ".$cmd", o: {create: orig, temp: 1}}]}));
assert(istemp(orig));

db.adminCommand({renameCollection: ns(orig), to: ns(dest)});
assert(!istemp(dest));

db[dest].drop();

assert.commandWorked(
    db.runCommand({applyOps: [{op: "c", ns: db.getName() + ".$cmd", o: {create: orig, temp: 1}}]}));
assert(istemp(orig));

db.adminCommand({renameCollection: ns(orig), to: ns(dest), stayTemp: true});
assert(istemp(dest));