Mongoose 分页查询:
在Schema中创建静态方法:
1. // 分页
2. CategorieSchema.statics = {
3. fetch(id, cb) {
4. if (id) {
5. return this.find({'_id': {"$lt": id}})
6. .limit(5)
7. .sort({'_id':-1})
8. .exec(cb);
9. }else {
10. return this.find({})
11. .limit(5)
12. .sort({'_id':-1})
13. .exec(cb);
14. }
15.
16. }
17. }
使用直接传id进入,或者 初始化传空值
1. DB.n_categorie.fetch(id,function (err,result) {
2. console.log(result);
3. });