diff options
author | Michael Ivanov <michael.karn.ivanov@gmail.com> | 2014-09-18 17:40:55 +0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2014-11-14 15:35:14 -0500 |
commit | a57241b5823968515be18614b1358e4bd7db5acc (patch) | |
tree | 077411b63a00b2adc0996cbe70ef8c7ca38da97e /jstests/core/count11.js | |
parent | 7556a05d67e1cb53503e7087e2a8c3b49a1a1503 (diff) | |
download | mongo-a57241b5823968515be18614b1358e4bd7db5acc.tar.gz |
SERVER-8514 return error on invalid count query on empty collection
Closes #783
Signed-off-by: Benety Goh <benety@mongodb.com>
Diffstat (limited to 'jstests/core/count11.js')
-rw-r--r-- | jstests/core/count11.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/jstests/core/count11.js b/jstests/core/count11.js new file mode 100644 index 00000000000..14392b9d90c --- /dev/null +++ b/jstests/core/count11.js @@ -0,0 +1,26 @@ +// SERVER-8514: Test the count command returns an error to the user when given an invalid query +// predicate, even when the collection doesn't exist. + +var t = db.count11; + +t.drop(); + +var validQuery = {a: 1}; +var invalidQuery = {a: {$invalid: 1}}; + +// Query non-existing collection with empty query. +assert.eq(0, t.find().count()); +assert.eq(0, t.find().itcount()); + +// Query non-existing collection. +// Returns 0 on valid syntax query. +// Fails on invalid syntax query. +assert.eq(0, t.find(validQuery).count()); +assert.throws(function() { t.find(invalidQuery).count(); }); + +// Query existing collection. +// Returns 0 on valid syntax query. +// Fails on invalid syntax query. +assert.commandWorked(db.createCollection(t.getName())); +assert.eq(0, t.find(validQuery).count()); +assert.throws(function() { t.find(invalidQuery).count(); }); |