分页在静态内不起作用"/>
猫鼬分页在静态内不起作用
我正在尝试使用mongoose-paginate
方法中的statics
,但是它抛出
TypeError:this.paginate不是函数\ n
我在节点v10.0.0上
"mongoose": "^4.9.7",
mongoose-paginate": "^5.0.3",
下面是我的代码,我想念什么?
const mongoose = require("mongoose");
var CarSchema = new mongoose.Schema({
showroom: {
type: String,
required: true,
index: true
},
doors: {
type: String,
required: true
}});
var paginate = require('mongoose-paginate');
CarSchema.plugin(paginate);
CarSchema.statics = {
list({ page = 1, perPage = 30, name, email, role }) {
const options = omitBy({ name, email, role }, isNil);
// this.paginate is undefined here
return this.paginate(options)
.sort({ createdAt: -1 })
.skip(perPage * (page - 1))
.limit(perPage)
.exec();
}
回答如下:
更多推荐
猫鼬分页在静态内不起作用
发布评论