summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-03-14 18:49:43 -0400
committerDavid Storch <david.storch@10gen.com>2015-03-18 10:01:44 -0400
commit4049c8328c98d8eb2b84fffca43ff4904e936909 (patch)
treef6819274232596c3bb2d3df0fb5b89fcde344c71 /jstests/noPassthroughWithMongod
parent465ca1774ddb7078566cb2edf0408f5881d6aae3 (diff)
downloadmongo-4049c8328c98d8eb2b84fffca43ff4904e936909.tar.gz
SERVER-17282 implement FindCmd::run()
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/find_cmd.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/find_cmd.js b/jstests/noPassthroughWithMongod/find_cmd.js
new file mode 100644
index 00000000000..00e4d315791
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/find_cmd.js
@@ -0,0 +1,49 @@
+// 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.
+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().getMongo(), 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"}}));