mongo/jstests/core/query/array/arrayfindb.js
Steve McClure 1ffbc6c2e9 SERVER-109432: Autofix JS var usage to favor let (#40637)
GitOrigin-RevId: 9674b7db36a0f3f650d39c1e3fb2ad6ff2141cfb
2025-08-28 19:21:01 +00:00

47 lines
1.2 KiB
JavaScript

// Test $elemMatch object with complex embedded expressions.
// @tags: [
// requires_getmore,
// ]
let t = db.jstests_arrayfindb;
t.drop();
// Case #1: Ensure correct matching for $elemMatch with an embedded $and (SERVER-13664).
t.save({
a: [
{b: 1, c: 25},
{a: 3, b: 59},
],
});
assert.eq(
0,
t.find({a: {$elemMatch: {b: {$gte: 2, $lt: 4}, c: 25}}}).itcount(),
"Case #1: wrong number of results returned -- unindexed",
);
t.createIndex({"a.b": 1, "a.c": 1});
assert.eq(
0,
t.find({a: {$elemMatch: {b: {$gte: 2, $lt: 4}, c: 25}}}).itcount(),
"Case #1: wrong number of results returned -- indexed",
);
// Case #2: Ensure correct matching for $elemMatch with an embedded $or.
t.drop();
t.save({a: [{b: 1}, {c: 1}]});
t.save({a: [{b: 2}, {c: 1}]});
t.save({a: [{b: 1}, {c: 2}]});
assert.eq(
2,
t.find({a: {$elemMatch: {$or: [{b: 2}, {c: 2}]}}}).itcount(),
"Case #2: wrong number of results returned -- unindexed",
);
t.createIndex({"a.b": 1});
t.createIndex({"a.c": 1});
assert.eq(
2,
t.find({a: {$elemMatch: {$or: [{b: 2}, {c: 2}]}}}).itcount(),
"Case #2: wrong number of results returned -- indexed",
);