MongoDB {aggregation $match} vs {find} speed

前端 未结 2 1622
傲寒
傲寒 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:01

    The main purpose of the aggregation framework is to ease the query of a big number of entries and generate a low number of results that hold value to you.

    As you have said, you can also use multiple find queries, but remember that you can not create new fields with find queries. On the other hand, the $group stage allows you to define your new fields.

    If you would like to achieve the functionality of the aggregation framework, you would most likely have to run an initial find (or chain several ones), pull that information and further manipulate it with a programming language.

    The aggregation pipeline might seem to take longer, but at least you know you only have to take into account the performance of one system - MongoDB engine.

    Whereas, when it comes to manipulating the data returned from a find query, you would most likely have to further manipulate the data with a programming language, thus increasing the complexity depending on the intricacies of the programming language of choice.

提交回复
热议问题