diff options
Diffstat (limited to 'jstests/core/query/count/count11.js')
-rw-r--r-- | jstests/core/query/count/count11.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/jstests/core/query/count/count11.js b/jstests/core/query/count/count11.js new file mode 100644 index 00000000000..f7eb398c6cb --- /dev/null +++ b/jstests/core/query/count/count11.js @@ -0,0 +1,34 @@ +// Cannot implicitly shard accessed collections because of collection existing when none +// expected. +// @tags: [assumes_no_implicit_collection_creation_after_drop, requires_fastcount] + +// 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(); +}); |