Closed yi closed 10 years ago
Hi @yi ,
Im happy to see you creating this first issue :) congratz.
The .paginate method takes an expressjs req object and uses the query object(parsed querystring) and this is where your code breaks
This should do the trick for your case
// just to clarify
var paginator = require('mongoose-paginator');
TicketSchema.plugins(paginator);
TicketSchema.statics.list = function(status, after, callback) {
var where, q;
where = [];
q = { query: {}};
if (STATUS.isValid(status)) {
where.push({
status: status
});
}
if (after != null) {
q.query.after = after;
}
where = {
$and: where
};
return this.paginate(q, '_id').where(where).execPagination(callback);
};
Hi Jonlil,
Thanks for your reply. That solves my problem.
And personally, I would suggest to decouple from express js. That I think it will be better for paginator to take the req.body as input parameter rather then the whole req.
Cheers
Hi yi, thank you for tour input. I have consider this but waited with it. And your suggestion makes perfect sense so I will implement it asap.
The paginator as it is at the moment uses req.query and not req.body, this is just to clarify
NICE :+1:
Hi, I wish to use mongodb query operators alone with your paginate. But I can't find a proper way to mix them in.
Following is my code:
and I got following error in execution: