2011-07-31 08:45:26 -07:00
|
|
|
// Test indexed elemmatch of missing field.
|
|
|
|
|
|
|
|
|
|
let t = db.jstests_arrayfind5;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
function check(nullElemMatch) {
|
|
|
|
|
assert.eq(1, t.find({'a.b': 1}).itcount());
|
|
|
|
|
assert.eq(1, t.find({a: {$elemMatch: {b: 1}}}).itcount());
|
|
|
|
|
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);
|
2020-11-17 13:45:05 +00: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);
|
2020-11-17 13:45:05 +00:00
|
|
|
t.createIndex({'a.b': 1});
|
2016-03-09 12:17:50 -05:00
|
|
|
check(false);
|