Files
mongo/jstests/core/query/count/count2.js
Joshua Siegel 169f8dc283 SERVER-111817 Add tag to exclude tests from timeseries CRUD suite (#44113)
GitOrigin-RevId: a3ab3b89275fa89c9824f6af467d56d605096159
2025-11-21 18:08:16 +00:00

35 lines
1.2 KiB
JavaScript

// @tags: [
// requires_getmore,
// requires_fastcount,
// # Cursor manipulation incompatible on timeseries with count 'applySkipLimit' option.
// exclude_from_timeseries_crud_passthrough,
// ]
const coll = db.count2;
coll.drop();
for (let i = 0; i < 1000; i++) {
assert.commandWorked(coll.insert({num: i, m: i % 20}));
}
assert.eq(1000, coll.count());
assert.eq(1000, coll.find().count());
assert.eq(1000, coll.find().toArray().length);
assert.eq(50, coll.find({m: 5}).toArray().length);
assert.eq(50, coll.find({m: 5}).count());
assert.eq(40, coll.find({m: 5}).skip(10).toArray().length);
assert.eq(50, coll.find({m: 5}).skip(10).count());
assert.eq(40, coll.find({m: 5}).skip(10).count(true));
assert.eq(20, coll.find({m: 5}).skip(10).limit(20).toArray().length);
assert.eq(50, coll.find({m: 5}).skip(10).limit(20).count());
assert.eq(20, coll.find({m: 5}).skip(10).limit(20).count(true));
assert.eq(5, coll.find({m: 5}).skip(45).limit(20).count(true));
// Negative skip values should return error
let negSkipResult = db.runCommand({count: coll.getName(), skip: -2});
assert(!negSkipResult.ok, "negative skip value shouldn't work, n = " + negSkipResult.n);
assert(negSkipResult.errmsg.length > 0, "no error msg for negative skip");