summaryrefslogtreecommitdiff
path: root/jstests/core/query/count/counta.js
blob: b1846233e352cb1a18a88f569496d5959234dc74 (plain)
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
// Check that count returns 0 in some exception cases.
//
// @tags: [
//   requires_fastcount
// ]

(function() {
'use strict';

var t = db.jstests_counta;
t.drop();

for (var i = 0; i < 10; ++i) {
    t.save({a: i});
}

// f() is undefined, causing an assertion
assert.throws(function() {
    t.count({
        $where: function() {
            if (this.a < 5) {
                return true;
            } else {
                f();
            }
        }
    });
});

// count must return error if collection name is absent
assert.commandFailedWithCode(db.runCommand("count"), ErrorCodes.InvalidNamespace);
})();