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
|
(function() {
if (typeof getToolTest === "undefined") {
load('jstests/configs/plain_28.config.js');
}
// Tests running mongoexport with --sort and --skip specified.
jsTest.log('Testing exporting with --sort and --skip');
var toolTest = getToolTest('sort_and_skip');
var commonToolArgs = getCommonToolArguments();
// the export target
var exportTarget = 'sort_and_skip_export.json';
removeFile(exportTarget);
// the db and collection we'll use
var testDB = toolTest.db.getSiblingDB('test');
var testColl = testDB.data;
// insert some data, in a different order than we'll be sorting it
for (var i = 30; i > 20; i--) {
testColl.insert({a: i});
}
for (i = 31; i < 50; i++) {
testColl.insert({a: i});
}
for (i = 20; i >= 0; i--) {
testColl.insert({a: i});
}
// sanity check the insertion worked
assert.eq(50, testColl.count());
// export the data, using --skip
var ret = toolTest.runTool.apply(toolTest, ['export',
'--out', exportTarget,
'--db', 'test',
'--collection', 'data',
'--sort', '{a:1}',
'--skip', '20']
.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 skip was applied to the export, and that
// the sort functioned so that the correct documents
// were skipped
assert.eq(30, testColl.count());
for (i = 20; i < 50; i++) {
assert.eq(1, testColl.count({a: i}));
}
// success
toolTest.stop();
}());
|