diff options
author | Katherine Wu <katherine.wu@mongodb.com> | 2019-12-24 00:48:39 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-12-24 00:48:39 +0000 |
commit | 5aed315a24e042cd34473da49cacd5dfbe263355 (patch) | |
tree | a3ce3d7d12eb09fb94cd6b36d14938b14b88edfe /jstests/core/count.js | |
parent | fed9387f2ee2745e2c25b8f94e3c337778770af2 (diff) | |
download | mongo-5aed315a24e042cd34473da49cacd5dfbe263355.tar.gz |
SERVER-42410 mongo shell count helper command throws errors on invalid options
Diffstat (limited to 'jstests/core/count.js')
-rw-r--r-- | jstests/core/count.js | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/jstests/core/count.js b/jstests/core/count.js index d0cfa377778..523b0743c3f 100644 --- a/jstests/core/count.js +++ b/jstests/core/count.js @@ -1,26 +1,37 @@ -// @tags: [requires_fastcount] - -t = db.jstests_count; - -t.drop(); -t.save({i: 1}); -t.save({i: 2}); -assert.eq(1, t.find({i: 1}).count(), "A"); -assert.eq(1, t.count({i: 1}), "B"); -assert.eq(2, t.find().count(), "C"); -assert.eq(2, t.find(undefined).count(), "D"); -assert.eq(2, t.find(null).count(), "E"); -assert.eq(2, t.count(), "F"); - -t.drop(); -t.save({a: true, b: false}); -t.ensureIndex({b: 1, a: 1}); -assert.eq(1, t.find({a: true, b: false}).count(), "G"); -assert.eq(1, t.find({b: false, a: true}).count(), "H"); - -t.drop(); -t.save({a: true, b: false}); -t.ensureIndex({b: 1, a: 1, c: 1}); - -assert.eq(1, t.find({a: true, b: false}).count(), "I"); -assert.eq(1, t.find({b: false, a: true}).count(), "J"); +// @tags: [requires_fastcount, assumes_against_mongod_not_mongos] + +(function() { +"use strict"; + +const coll = db.jstests_count; + +coll.drop(); +assert.commandWorked(coll.insert({i: 1})); +assert.commandWorked(coll.insert({i: 2})); +assert.eq(1, coll.find({i: 1}).count()); +assert.eq(1, coll.count({i: 1})); +assert.eq(2, coll.find().count()); +assert.eq(2, coll.find(undefined).count()); +assert.eq(2, coll.find(null).count()); +assert.eq(2, coll.count()); + +coll.drop(); +assert.commandWorked(coll.insert({a: true, b: false})); +assert.commandWorked(coll.ensureIndex({b: 1, a: 1})); +assert.eq(1, coll.find({a: true, b: false}).count()); +assert.eq(1, coll.find({b: false, a: true}).count()); + +coll.drop(); +assert.commandWorked(coll.insert({a: true, b: false})); +assert.commandWorked(coll.ensureIndex({b: 1, a: 1, c: 1})); + +assert.eq(1, coll.find({a: true, b: false}).count()); +assert.eq(1, coll.find({b: false, a: true}).count()); + +// Make sure that invalid options passed into the shell count helper generate errors. +assert.eq(assert.throws(() => coll.count({}, {random: true})).code, 40415); + +// Test that a string passed into count will be converted into a $where clause. +assert.eq(1, coll.count("this.a")); +assert.eq(0, coll.count("this.b")); +})(); |