我想做猫鼬填充,但是根据我的模式它在下面不起作用。我该如何解决这个问题?为什么它不起作用,我在stackoverflow上使用了许多解决方案,但是即使我读出了对我也不起作用的文档,也都无法使用。现在有人可以帮助我如何分类?
验证
const authSchema = mongoose.Schema({
first_name: {
type: String
},
last_name: {
type: String
},
});
const auth = mongoose.model('auth', authSchema);
项目
const teamSchema = mongoose.Schema({
auth_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'auth'
}
});
const projectSchema = mongoose.Schema({
team: {
type: [ teamSchema ]
}
});
const project = mongoose.model('project', projectSchema);
查询:
project.find({}).populate(team.$.auth_id).exec((err, result) => {
if(err) rej(err);
res(result);
});
答案 0 :(得分:0)
根据文档,您应该执行以下操作:
project.find({}).populate('team').exec.....
或project.find({}).populate('auth_id').exec.....
如果您要过滤特定的auth_id,则条件应位于查找中而不是填充中,显然填充将接收要填充的键名
https://mongoosejs.com/docs/populate.html
希望获得帮助