summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/temp_namespace.js
blob: f33d2abfd766fc7d3d1b3e1dd682f5811ed262bc (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
// this is to make sure that temp collections get cleaned up on restart.
//
// This test requires persistence beacuase it assumes data will survive a restart.
// @tags: [requires_persistence, requires_replication]

testname = 'temp_namespace_sw';

var conn = MongoRunner.runMongod();
d = conn.getDB('test');
assert.commandWorked(d.runCommand({
    applyOps:
        [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'temp1', temp: true}}]
}));
d[testname + 'temp1'].ensureIndex({x: 1});
assert.commandWorked(d.runCommand(
    {applyOps: [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'temp2', temp: 1}}]}));
d[testname + 'temp2'].ensureIndex({x: 1});
assert.commandWorked(d.runCommand({
    applyOps:
        [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'keep1', temp: false}}]
}));
assert.commandWorked(d.runCommand(
    {applyOps: [{op: "c", ns: d.getName() + ".$cmd", o: {create: testname + 'keep2', temp: 0}}]}));
d.runCommand({create: testname + 'keep3'});
d[testname + 'keep4'].insert({});

function countCollectionNames(theDB, regex) {
    return theDB.getCollectionNames()
        .filter(function(z) {
            return z.match(regex);
        })
        .length;
}

assert.eq(countCollectionNames(d, /temp\d$/), 2);
assert.eq(countCollectionNames(d, /keep\d$/), 4);
MongoRunner.stopMongod(conn);

conn = MongoRunner.runMongod({
    restart: true,
    cleanData: false,
    dbpath: conn.dbpath,
});
d = conn.getDB('test');
assert.eq(countCollectionNames(d, /temp\d$/), 0);
assert.eq(countCollectionNames(d, /keep\d$/), 4);
MongoRunner.stopMongod(conn);