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

编程入门 行业动态 更新时间:2024-10-07 14:33:06

猫鼬<a href=https://www.elefans.com/category/jswz/34/1769545.html style=分页在静态内不起作用"/>

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

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

更多推荐

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

本文发布于:2024-05-13 09:23:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   静态   不起作用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!