Files
mongo/jstests/core/query/count/count4.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

27 lines
776 B
JavaScript

// @tags: [
// requires_getmore,
// ]
const t = db.count4;
t.drop();
let docs = [];
for (let i = 0; i < 100; i++) {
docs.push({_id: i, x: i});
}
assert.commandWorked(t.insert(docs));
const q = {
x: {$gt: 25, $lte: 75},
};
assert.eq(50, t.find(q).count(), "collection scan fast count: " + tojson(q));
assert.eq(50, t.find(q).itcount(), "collection scan find iterator count: " + tojson(q));
assert.eq(50, t.countDocuments(q), "collection scan aggregation count: " + tojson(q));
assert.commandWorked(t.createIndex({x: 1}));
assert.eq(50, t.find(q).count(), "index scan fast count: " + tojson(q));
assert.eq(50, t.find(q).itcount(), "index scan find iterator count: " + tojson(q));
assert.eq(50, t.countDocuments(q), "index scan aggregation count: " + tojson(q));