How can you optimize queries?

  • Create an index to cover fields used in query
  • Syntax:
    db.collection.ensureIndex({field:1})
    1 = ascending, -1 = descending
  •  
  • Use limit() to reduce number of documents returned
  • Use projections to limit fields returned
  • Use explain() to analyze performance
  • Use hint() to force MongoDB to use a particular index






>>
 


+ o -