I was creating compound indexes in mongodb, I found a weird behaviour. I created an Index:
db.getCollection('Subject').createIndex({a:1, b:2, c:3})
it created an index named a_1_b_2_c_3
.
Now when i am using the mongo find command:
db.getCollection('Subject').find({a:1, b:2, c:3}) //it works fine `a_1_b_2_c_3` is used.
db.getCollection('Subject').find({a:1, b:2}) //this also works fine `a_1_b_2_c_3` is used.
db.getCollection('Subject').find({a:1, c:2}) //this also works fine `a_1_b_2_c_3` is used.
db.getCollection('Subject').find({b:1, c:2}) //But this command doesn't uses the index `a_1_b_2_c_3`.
can anyone let me know why this kind of behaviour is happening?