2011-07-31 08:45:26 -07:00
|
|
|
// Test indexed elemmatch of missing field.
|
2024-12-27 16:01:08 +04:00
|
|
|
// @tags: [
|
|
|
|
|
// requires_getmore
|
|
|
|
|
// ]
|
2011-07-31 08:45:26 -07:00
|
|
|
|
|
|
|
|
let t = db.jstests_arrayfind5;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
function check(nullElemMatch) {
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.eq(1, t.find({"a.b": 1}).itcount());
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(1, t.find({a: {$elemMatch: {b: 1}}}).itcount());
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.eq(nullElemMatch ? 1 : 0, t.find({"a.b": null}).itcount());
|
|
|
|
|
assert.eq(nullElemMatch ? 1 : 0, t.find({a: {$elemMatch: {b: null}}}).itcount()); // see SERVER-3377
|
2011-07-31 08:45:26 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{}, {b: 1}]});
|
|
|
|
|
check(true);
|
2025-08-21 10:17:44 -07:00
|
|
|
t.createIndex({"a.b": 1});
|
2016-03-09 12:17:50 -05:00
|
|
|
check(true);
|
2011-07-31 08:45:26 -07:00
|
|
|
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [5, {b: 1}]});
|
|
|
|
|
check(false);
|
2025-08-21 10:17:44 -07:00
|
|
|
t.createIndex({"a.b": 1});
|
2016-03-09 12:17:50 -05:00
|
|
|
check(false);
|