populate with mongoose pagination populate with mongoose pagination mongoose mongoose

populate with mongoose pagination


If you want to use mongoose-paginate, You can do the following

var query = {};var options = {  sort: { date: -1 },  populate: 'users',  lean: true,  offset: offset,   limit: 10};Post.paginate({}, options, (err, result) => { //....})


A populate have following things

Post.find({}).populate([    // here array is for our memory.     // because may need to populate multiple things    {        path: 'user',        select: 'name',        model:'User',        options: {            sort:{ },            skip: 5,            limit : 10        },        match:{            // filter result in case of multiple result in populate            // may not useful in this case        }    }]).exec((err, results)=>{   console.log(err, results)})