File: dumprestoreWithNoOptions.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (105 lines) | stat: -rw-r--r-- 3,388 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SERVER-6366
// relates to SERVER-808
//
// This file tests that options are not restored upon
// mongorestore with --noOptionsRestore
//
// It checks that this works both when doing a full
// database dump/restore and when doing it just for a
// single db or collection.

t = new ToolTest( "dumprestoreWithNoOptions" );

t.startDB( "foo" );
db = t.db;

dbname = db.getName();
dbname2 = "NOT_"+dbname;

db.dropDatabase();

var options = { capped: true, size: 1000, autoIndexId: true };
db.createCollection('capped', options);
assert.eq( 1, db.system.indexes.count(), "auto index not created" );
var cappedOptions = db.capped.exists().options;
for ( var opt in options ) {
  assert.eq(options[opt], cappedOptions[opt], 'invalid option')
}
db.capped.insert({ x: 1 });
db.getLastError()

// Full dump/restore

t.runTool( "dump" , "--out" , t.ext );

db.dropDatabase();
assert.eq( 0, db.capped.count(), "capped not dropped");
assert.eq( 0, db.system.indexes.count(), "indexes not dropped" );

t.runTool( "restore" , "--dir" , t.ext , "--noOptionsRestore");

assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
assert(true !== db.capped.stats().capped, "restore options were not ignored");
assert(undefined === db.capped.exists().options, "restore options not ignored");

// Dump/restore single DB

db.dropDatabase();
var options = { capped: true, size: 1000, autoIndexId: true };
db.createCollection('capped', options);
assert.eq( 1, db.system.indexes.count(), "auto index not created" );
var cappedOptions = db.capped.exists().options;
for ( var opt in options ) {
  assert.eq(options[opt], cappedOptions[opt], 'invalid option')
}
db.capped.insert({ x: 1 });
db.getLastError()

dumppath = t.ext + "noOptionsSingleDump/";
mkdir(dumppath);
t.runTool( "dump" , "-d", dbname, "--out" , dumppath );

db.dropDatabase();
assert.eq( 0, db.capped.count(), "capped not dropped");
assert.eq( 0, db.system.indexes.count(), "indexes not dropped" );

t.runTool( "restore" , "-d", dbname2, "--dir" , dumppath + dbname, "--noOptionsRestore");

db = db.getSiblingDB(dbname2);

assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
assert(true !== db.capped.stats().capped, "restore options were not ignored");
assert(undefined === db.capped.exists().options, "restore options not ignored");

// Dump/restore single collection

db.dropDatabase();
var options = { capped: true, size: 1000, autoIndexId: true };
db.createCollection('capped', options);
assert.eq( 1, db.system.indexes.count(), "auto index not created" );
var cappedOptions = db.capped.exists().options;
for ( var opt in options ) {
  assert.eq(options[opt], cappedOptions[opt], 'invalid option')
}
db.capped.insert({ x: 1 });
db.getLastError()

dumppath = t.ext + "noOptionsSingleColDump/";
mkdir(dumppath);
dbname = db.getName();
t.runTool( "dump" , "-d", dbname, "-c", "capped", "--out" , dumppath );

db.dropDatabase();

assert.eq( 0, db.capped.count(), "capped not dropped");
assert.eq( 0, db.system.indexes.count(), "indexes not dropped" );

t.runTool( "restore", "-d", dbname, "--drop", "--noOptionsRestore", dumppath + dbname );

db = db.getSiblingDB(dbname);

assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
assert( true !== db.capped.stats().capped, "restore options were not ignored" );
assert( undefined === db.capped.exists().options );

t.stop();