【发布时间】:2018-06-07 12:51:32
【问题描述】:
我有一个如下所示的用户架构,我正在尝试填充实时项目数组,但我不知道如何访问它。
const userSchema = new Schema({
local: {
email: String,
username: String,
password: String,
liveProjects: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'liveProject'
}]
},
google: {
googleId: String,
email: String,
username: String,
liveProjects: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'liveProject'
}]
}
});
const User = mongoose.model('user', userSchema);
module.exports = User;
如果没有嵌入,我可以使用
User.findById(id).populate('liveProjects').exec((err,projects)=>{});
但是如何访问'local.liveProjects' 或'google.liveProjects' 以便填充它们?
【问题讨论】:
标签: node.js mongodb mongoose mongoose-populate