On Thursday, October 11, 2012 4:39:21 PM UTC+1, Kevin Rice wrote:
> Hello!
db.collectionName.find({'FieldA':999}).sort({'FieldB': 1}) should use indextwo
If you
db.collectionName.find({'FieldA':999}).sort({'FieldB': 1}) .explain()
you will see which index is being used if any.
> Question re: index usage - I may have extraneous indexes if Mongo isn't using them, thus a slowdown on insert/update, thus the question:
>
> My sharded, replicated collection has uniform records with fields FieldA and FieldB. There are two indexes on this collection:
> IndexOne has key FieldA only.IndexTwo has keys FieldA and FieldB.Questions:
> On a db.collectionName.find({ 'FieldA' : 999}), I would figure Index IndexOne would be used.If IndexOne didn't exist and I did db.collectionName.find({ 'FieldA' : 999}), I would figure Index IndexTwo would be used.If I do db.collectionName.find({'FieldA':999}).sort({'FieldB': 1}) (plus or minus syntax here), which index would be used? If IndexOne doesn't exist, can the find().sort() call use IndexTwo?In Postgres, I can do an 'analyze explain <queryOne>' that shows me what index it uses for queryOne. How do I do this in Mongo?