Another option is to limit the results at the application level, rather than in the Mongo query. Then you can get a count of the full result, and you do not need to make two calls.
For example, in Python you would do:
data = db.orders.aggregate([{ "$match" : { "status": "A"} }])['result'] count = len(data) data = data[skip:skip+limit]
If you have a complex shared call on a large dataset, this is significantly faster than making two calls.
Valerie R. Coffman
source share