key: {$exists: false} / key: {$type: 10} / key: null quering gives inconsistent and unpredictable behaviour, so to workraound needed to implement querying of this kind of parameters
shell script example:
db.testcollection.ensureIndex(
,
{unique: 1, background: 1});
db.testcollection.insert(
);
db.testcollection.insert(
);
db.testcollection.insert(
);
db.testcollection.insert(
);
db.testcollection.insert(
);
db.testcollection.insert(
);
db.testcollection.find(
{date: new Date("08/27/2010")}).count(); // 6 [OK]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}}).count(); // 5 [OK]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: false}}).count(); // 1 [OK]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$type: 10}}).count(); // 1 [OK]
db.testcollection.find(
).count(); // 1 [OK]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$exists: true}}).count(); // 3 [OK]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$exists: false}}).count(); // 2 [OK]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$type: 10}}).count(); // 0 [??]
db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: null}).count(); // 2 [OK]
changing the order of key querying or indexing produces slightly different results, always bogus
- depends on
-
SERVER-1587 $exists:false not working correctly
- Closed