与mongoose Paginate插件一起使用mongoose.populate

时间:2018-10-23 05:21:43

标签: node.js mongodb mongoose mongoose-populate

我的模式是这样的

 let serviceItemSchema = new mongoose.Schema(
  {
    "name": {
      type: String,
      required: true
    },
    "description": {
      type: String,
      required: true
    },
    "categoryIds": {
      type: Array,
      required: true
    },
    "tags": {
      type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'tags' }]
    }
  },
  { timestamps: true, strict: false }
);

我要使用像这样的猫鼬

serviceItem.paginate(searchQuery, req.options)
  .populate('tags')
    .then((response, err) => {
      if (err) {
        next(err);
      } else {
        next(null, response);
      }
    })

它不起作用,需要一些帮助。

谢谢

0 个答案:

没有答案