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
|
(function() {
if (typeof getToolTest === 'undefined') {
load('jstests/configs/plain_28.config.js');
}
// Tests running mongoexport with different data types, and bringing it back
// in with import.
jsTest.log('Testing exporting, then importing, different data types');
var toolTest = getToolTest('data_types');
var commonToolArgs = getCommonToolArguments();
// the export target
var exportTarget = 'data_types_export.json';
removeFile(exportTarget);
// the db and collection we'll use
var testDB = toolTest.db.getSiblingDB('test');
var testColl = testDB.data;
// insert some data, of different types
testColl.insert({num: 1});
testColl.insert({flt: 1.0});
testColl.insert({str: '1'});
testColl.insert({obj: {a: 1}});
testColl.insert({arr: [0, 1]});
testColl.insert({bd: new BinData(0, '1234')});
testColl.insert({date: ISODate('2009-08-27T12:34:56.789')});
testColl.insert({ts: new Timestamp(1234, 5678)});
testColl.insert({rx: /foo*"bar"/i});
// sanity check the insertion worked
assert.eq(9, 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(9, testColl.count());
assert.eq(1, testColl.count({num: 1}));
assert.eq(1, testColl.count({flt: 1.0}));
assert.eq(1, testColl.count({str: '1'}));
assert.eq(1, testColl.count({obj: {a: 1}}));
assert.eq(1, testColl.count({arr: [0, 1]}));
assert.eq(1, testColl.count({bd: new BinData(0, '1234')}));
assert.eq(1, testColl.count({date: ISODate('2009-08-27T12:34:56.789')}));
assert.eq(1, testColl.count({ts: new Timestamp(1234, 5678)}));
assert.eq(1, testColl.count({rx: {$exists: true}}));
// success
toolTest.stop();
}());
|