summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/test/qa-tests/jstests/export/basic_data.js
blob: c0be94f8a553dfa6cac268213ccf87eb6796533d (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
55
56
57
58
(function() {

  if (typeof getToolTest === 'undefined') {
    load('jstests/configs/plain_28.config.js');
  }

  // Tests running mongoexport with some basic data, and bringing it back
  // in with import.

  jsTest.log('Testing exporting, then importing, some basic data');

  var toolTest = getToolTest('basic_data');
  var commonToolArgs = getCommonToolArguments();

  // the export target
  var exportTarget = 'basic_data_export.json';
  removeFile(exportTarget);

  // the db and collection we'll use
  var testDB = toolTest.db.getSiblingDB('test');
  var testColl = testDB.data;

  // insert some data
  for (var i = 0; i < 50; i++) {
    testColl.insert({_id: i});
  }
  // sanity check the insertion worked
  assert.eq(50, testColl.count());

  // export the data
  var ret = toolTest.runTool.apply(toolTest, ['export',
      '--out', exportTarget,
      '--db', 'test',
      '--collection', 'data']
    .concat(commonToolArgs));
  assert.eq(0, ret);

  // drop the database
  testDB.dropDatabase();

  // import the data back in
  ret = toolTest.runTool.apply(toolTest, ['import',
      '--file', exportTarget,
      '--db', 'test',
      '--collection', 'data']
    .concat(commonToolArgs));
  assert.eq(0, ret);

  // make sure the data is correct
  assert.eq(50, testColl.count());
  for (i = 0; i < 50; i++) {
    assert.eq(1, testColl.count({_id: i}));
  }

  // success
  toolTest.stop();

}());