mongo/jstests/core/query/array/arrayfind2.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

31 lines
822 B
JavaScript

// @tags: [requires_fastcount]
let t = db.arrayfind2;
t.drop();
function go(prefix) {
assert.eq(3, t.count(), prefix + " A1");
assert.eq(3, t.find({a: {$elemMatch: {x: {$gt: 4}}}}).count(), prefix + " A2");
assert.eq(1, t.find({a: {$elemMatch: {x: {$lt: 2}}}}).count(), prefix + " A3");
assert.eq(
1,
t.find({a: {$all: [{$elemMatch: {x: {$lt: 4}}}, {$elemMatch: {x: {$gt: 5}}}]}}).count(),
prefix + " A4",
);
assert.throws(function () {
return t.findOne({a: {$all: [1, {$elemMatch: {x: 3}}]}});
});
assert.throws(function () {
return t.findOne({a: {$all: [/a/, {$elemMatch: {x: 3}}]}});
});
}
t.save({a: [{x: 1}, {x: 5}]});
t.save({a: [{x: 3}, {x: 5}]});
t.save({a: [{x: 3}, {x: 6}]});
go("no index");
t.createIndex({a: 1});
go("index(a)");