最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

猫鼬分页在静态内不起作用

网站源码admin32浏览0评论

猫鼬分页在静态内不起作用

猫鼬分页在静态内不起作用

我正在尝试使用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();
  }
回答如下:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论