Files
mongo/jstests/core/query/count/counta.js
Jan 63b37a01c1 SERVER-71453 Change count command from BasicCommand to IDL typed command (#26579)
GitOrigin-RevId: acee6edd54d71d692d32e4b4b460c93e4218b4b3
2024-09-20 15:14:01 +00:00

31 lines
683 B
JavaScript

// Check that count returns 0 in some exception cases.
//
// @tags: [
// requires_fastcount
// ]
const t = db.jstests_counta;
t.drop();
for (let 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 {
// eslint-disable-next-line
f();
}
}
});
});
// count must return error if collection name is absent
assert.commandFailedWithCode(db.runCommand("count"),
[ErrorCodes.InvalidNamespace, ErrorCodes.TypeMismatch]);