Skip to content

Why use aggregation to paginate? #1056

Closed
@limen

Description

@limen

Get rows from collection with pagination.

  • Use aggregation
    db.{dbname}.aggregate([{$sort:{_id:-1}}, {$skip:2}, {$limit:2}]);
  • Not use aggregation
    db.{dbname}.find().sort({"_id":-1}).skip(2).limit(2)
    The returned data sets are all the same but the time consumption are very different. So why use aggregation to paginate?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions