Files
mongo/jstests/core/query/count/counta.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

30 lines
657 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]);