node.js - Pagination in Mongodb Nodejs -


is there method total count of document in find operation along skip , limit in query in mongodb

 mongoclient.connect(config.dburi, function (err, db) {     if (!err) {         console.log("we connected");         console.log(uniqueid)         db.collection(dbname).find({'uniqueid': uniqueid, 'isdeleted': false})             .sort({modifieddateiso: -1})             .limit(parseint(limit))             .skip(parseint(limit * page))             .toarray((errfindchat, datafindchat) => {                             console.log(errfindchat, datafindchat);       }); }); 

you can't filter skip , limit , have total count in 1 request if use .find..

if want retrieve documents, filter, , perform count operation in 1 request have use aggregate

db.coll.aggregate([ {$match: find conditions}, {$group/project: count operations, etc....}, {$skip: skip}, // pagination skip {$limit: limit}, // pagination limit ... ]); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -