猫鼬填充查询条件“匹配”不起作用

时间:2020-03-24 10:43:34

标签: mongodb mongoose mongoose-populate

这是我的架构:

const Schema = mongoose.Schema

const CommentsSchema = new Schema({
  tid: { type: String, ref: 'post' },
  uid: { type: String, ref: 'users' },
  cuid: { type: String, ref: 'users' },
  content: { type: String },
  created: { type: Date },
}, { toJSON: { virtuals: true } })

用户架构:

const UserSchema = new Schema({
  username: { type: String, index: { unique: true }, sparse: true },
  password: { type: String },
  name: { type: String },
  created: { type: Date },
  updated: { type: Date }
})

问题:

按照官方文档:https://mongoosejs.com/docs/populate.html#query-conditions,将match添加到我的find方法中:

this.find(query)
.populate({
  path: 'uid',
  select: '_id name',
  match: { name: new RegExp('admin', 'i') }
})
.skip(page * limit)
.limit(limit)
.sort({ created: -1 })

结果为空。但是,我有一些admin创建的评论。而且我可以在没有match大小写的情况下进行填充。

为什么?

0 个答案:

没有答案