Laravel-mongodb: Why use aggregation to paginate?

Created on 12 Dec 2016  路  6Comments  路  Source: jenssegers/laravel-mongodb

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?

Most helpful comment

mongodb is used for performance mainly, but using aggregate instead of find is killing the purpose.
+1

All 6 comments

with millions of records pagination took very long time ......

Yes, this is issue, with millions of records total aggregation is slow.

@jenssegers is there any plans to count totals with count instead of aggregation?

Ofcourse, it is possible to write custom paginator, but still I'm wondering do you have this issue in to-do list.

Had this issue as well, had to leave pagination to left/right only otherwise it would time out on collection with lots of documents..

+1, this issue still accouring till now

mongodb is used for performance mainly, but using aggregate instead of find is killing the purpose.
+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imrannazirbhat picture imrannazirbhat  路  3Comments

pirmax picture pirmax  路  3Comments

lgt picture lgt  路  3Comments

Vasiliy-Bondarenko picture Vasiliy-Bondarenko  路  3Comments

kschethan picture kschethan  路  3Comments