summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/legacy30/jstests/tool/dumprestore6.js
blob: 1ea55e40f5c8fb86e6fdb29c06fc85ff17af3ff9 (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
48
49
50
51
52
53
54
// dumprestore6.js
// Test restoring from a dump with an old index version


t = new ToolTest( "dumprestore6" );

c = t.startDB( "foo" );
db = t.db
if(db.serverStatus().storageEngine.name == "mmapv1") {
  assert.eq( 0 , c.count() , "setup1" );

  t.runTool("restore", "--dir", "jstests/tool/data/dumprestore6", "--db", "jstests_tool_dumprestore6")

  assert.soon( "c.findOne()" , "no data after sleep" );
  assert.eq( 1 , c.count() , "after restore" );

  var indexes = c.getIndexes();
  assert.eq( 2, indexes.length, "there aren't the correct number of indexes" );
  var aIndex = null;
  indexes.forEach(function(index) {
      if (index.name === "a_1") {
          aIndex = index;
      }
  });
  assert.neq(null, aIndex, "index doesn't exist" );
  assert.eq( 1 , aIndex.v, "index version wasn't updated");

  assert.eq( 1, c.count({v:0}), "dropped the 'v' field from a non-index collection")

  db.dropDatabase()
  assert.eq( 0 , c.count() , "after drop" );

  t.runTool("restore", "--dir", "jstests/tool/data/dumprestore6", "--db", "jstests_tool_dumprestore6", "--keepIndexVersion")

  assert.soon( "c.findOne()" , "no data after sleep2" );
  assert.eq( 1 , c.count() , "after restore2" );

  indexes = c.getIndexes();
  assert.eq( 2, indexes.length, "there aren't the correct number of indexes" );
  aIndex = null;
  indexes.forEach(function(index) {
      if (index.name === "a_1") {
          aIndex = index;
      }
  });
  assert.neq(null, aIndex, "index doesn't exist" );
  assert.eq( 0 , aIndex.v, "index version wasn't maintained")

  assert.eq( 1, c.count({v:0}), "dropped the 'v' field from a non-index collection")
}else{
  print("skipping index version test on non-mmapv1 storage engine")
}

t.stop();