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
|
// Basic tests for invoking the find command directly.
var coll = db.findcmd;
var collname = coll.getName();
coll.drop();
var res;
var cursor;
// Non-existent collection.
res = coll.runCommand("find");
assert.commandWorked(res);
assert.eq(0, res.cursor.id);
assert.eq([], res.cursor.firstBatch);
// Empty collection.
assert.commandWorked(coll.getDB().createCollection(collname));
res = coll.runCommand("find");
assert.commandWorked(res);
assert.eq(0, res.cursor.id);
assert.eq([], res.cursor.firstBatch);
// Ensure find command keeps cursor open if tailing a capped collection.
// Skip the test with mobile storage engine as it doesn't support capped collections.
if (jsTest.options().storageEngine !== "mobile") {
coll.drop();
assert.commandWorked(coll.getDB().createCollection(collname, {capped: true, size: 2048}));
assert.writeOK(coll.insert({_id: 1}));
res = coll.runCommand("find", {tailable: true});
assert.commandWorked(res);
assert.neq(0, res.cursor.id);
assert.eq([{_id: 1}], res.cursor.firstBatch);
}
// Multiple batches.
coll.drop();
for (var i = 0; i < 150; i++) {
assert.writeOK(coll.insert({_id: i}));
}
res = coll.runCommand("find", {filter: {_id: {$lt: 140}}});
assert.commandWorked(res);
assert.neq(0, res.cursor.id);
assert.eq(101, res.cursor.firstBatch.length);
cursor = new DBCommandCursor(coll.getDB(), res);
assert.eq(cursor.itcount(), 140);
// Command doesn't parse.
assert.commandFailed(coll.runCommand("find", {foo: "bar"}));
// Filter doesn't parse.
assert.commandFailed(coll.runCommand("find", {projection: {_id: 0}, filter: {$foo: "bar"}}));
// Special command namespace.
assert.commandFailed(coll.getDB().runCommand({find: "$cmd"}));
assert.commandFailed(coll.getDB().runCommand({find: "$cmd.sys.inprog"}));
|