Mongo aggregation with paginated data and totals

前端 未结 3 1261
日久生厌
日久生厌 2020-12-28 11:00

I\'ve crawled all over stack overflow, and have not found any info on how to return proper pagination data included in the resultset.

I\'m trying to aggregate some

3条回答
  •  萌比男神i
    2020-12-28 11:21

    A performance optimization tip:

    When you use $facet stage for pagination, Try to add it as soon as it's possible.

    For example: if you want to add $project or $lookup stage, add them after $facet, not before it.

    it will have impressive effect in aggregation speed. because $project stage require MongoDB to explore all documents and get involve with all fields(which is not necessary).

提交回复
热议问题