Is it possible to get the query results' count and limit docs in one query?

12 views
Skip to first unread message

Kim Chen

unread,
May 24, 2016, 9:12:05 AM5/24/16
to node-mongodb-native
I want to implement a pagination api but I don't know how people implements it.
Query how many documents are there in a collection :
db.collection.find().toArray((err,docs) => {docs.length});
or
db.collection.count(); will do.
And then, we can use the count to calculate remaining documents according to pagesize and current page. This's the first idea I had.
However, is there any way to get the count (or get the remaining count) and limit docs at a time? 
Something like :   db.collection.somequery(query).limit(10).skip(20).result(err, docs, account of query results or remaining account after skip 20 docs and showed 10 docs)
If you don't use either of these way, would you mind teach me how to implement this?
Thank you very much in advance!
Reply all
Reply to author
Forward
0 new messages