MongoDB {aggregation $match} vs {find} speed

前端 未结 2 1619
傲寒
傲寒 2020-12-02 16:38

I have a mongoDB collection with millions of rows and I\'m trying to optimize my queries. I\'m currently using the aggregation framework to retrieve data and group them as I

2条回答
  •  温柔的废话
    2020-12-02 17:20

    Have you tried using explain() to your find queries? It'll give you good idea about how much time find() query will exactly take. You can do the same for $match with $explain & see whether there is any difference in index accessing & other parameters.

    Also the $group part of aggregation framework doesn't utilize the indexing so it has to process all the records returned by $match stage of aggregation framework. So to better understand the the working of your query see the result set it returns & whether it fits into memory to be processed by MongoDB.

提交回复
热议问题