difference between aggregate ($match) and find, in MongoDB?

后端 未结 2 1491
死守一世寂寞
死守一世寂寞 2020-12-28 15:37

What is the difference between the $match operator used inside the aggregate function and the regular find in Mongodb?

Why doesn\'t the

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 16:08

    I investigated a few things about the aggregation and find call: I did this with a descending sort in a table of 160k documents and limited my output to a few documents.

    1. The Aggregation command is slower than the find command.
    2. If you access to the data like ToList() the aggregation command is faster than the find.
    3. if you watch at the total times (point 1 + 2) the commands seem to be equal

    Maybe the aggregation automatically calls the ToList() and does not have to call it again. If you dont call ToList() afterwards the find() call will be much faster.

    7 [ms] vs 50 [ms] (5 documents)

提交回复
热议问题