Since upgrading from 2.4 to 2.6 I've found indexes are causing some queries to produce incorrect values.

Our dataset is like this:

// This is a simplified harness to replicate what we're seeing in our DB /** number_user_id indexes **/ db.getCollection("number_user_id").ensureIndex({ "_id": NumberInt(1) },[]); /** number_user_id indexes **/ db.getCollection("number_user_id").ensureIndex({ "user_id": NumberLong(1) },[]); /** number_user_id indexes **/ db.getCollection("number_user_id").ensureIndex({ "number": NumberLong(1) },[]); /** number_user_id indexes **/ db.getCollection("number_user_id").ensureIndex({ "user_id": NumberLong(1), "number": NumberLong(1) },{ "unique": true }); /** number_user_id records **/ db.getCollection("number_user_id").insert({ "_id": ObjectId("537dc86a80f1cf0e42d63af1"), "number": null, "user_id": 1 }); db.getCollection("number_user_id").insert({ "_id": ObjectId("537dc87f80f1cf0f42d63af1"), "number": 2, "user_id": 1 }); db.getCollection("number_user_id").insert({ "_id": ObjectId("537dc87580f1cf0d42d63af1"), "number": 1, "user_id": 1 });

The query differences are as follows:

db.number_user_id.find({ $or: [{ number: null }, { number: { $lte: 2 } }] }); // On 2.4 you get all 3 documents back on 2.6 you get 1 document back db.number_user_id.find({ $or: [{ number: null }, { number: { $lte: 2 } }] }).count(); // On 2.4 you get 3 on 2.6 you get 1

If I remove the joint index I can get correct results but that comprimises data integrity.

I can't find this scenario in the docs/changelog. So I'm wondering whether I need to do different indexes, rewrite queries or if I've found a MongoDB bug.