DEV Community

Discussion on: The right way to make advanced and efficient MongoDB pagination

Collapse
 
malinda1986 profile image
malinda1986 • Edited

I'm wondering if you change the sort key to another attribute does that work ? I think sort order breaks at

{ records: { '$slice': [ '$data', -10, { '$ifNull': [ 10, '$total.source' ] } ] }, pagination: { total: '$total.source', limit: { '$literal': 10 }, page: { '$literal': 1 }, pages: { '$ceil': { '$divide': [ '$total.source', 10 ] } } } }

upto above stage sort order preserved . any suggestions to fix that ?