db.Order.aggregate([ { '$match' : { "company_id" : ObjectId("54c0...") } }, { '$sort' : { 'order_number' : -1 } }, { '$facet' : { metadata: [ { $count: "total" }, { $addFields: { page: NumberInt(3) } } ], data: [ { $skip: 20 }, { $limit: 10 } ] // add projection here wish you re-shape the docs } } ] )
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter