How cache is used in query execution?

Does system check PlanCache before every query execution?
Is there any other cache on which query performance is depending?

Hi @Monika_Shah,

MongoDB checks in the PlanCache to see if an optimal index has been chosen before or not for the given query

If not, then it

  • Picks all candidate indexes
  • Runs queries using them to score which is most efficient
  • Adds its choice of the best index to the PlanCache

There are some aggregation stages such as $lookup and $graphLookup which have their own document caches for their internal pipelines.

I hope it helps!


I am getting reduced execution time in simple Range query using find operation.

Hi :wave: @Monika_Shah,

Can you provide more details about what you mean by "reduced execution time" in this context? It seems like you may be comparing two queries, one of which has a faster execution time than the other. Could you please provide the following information:

  • The version of MongoDB you are using,
  • A sample document from your dataset,
  • The query you are running,
  • The explain('executionStats') output for both the faster and slower queries,
  • and the description of your deployment environment.

to better understand the requirements of the question.