这是我的架构:
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
大小写的情况下进行填充。
为什么?