【发布时间】:2018-12-15 06:15:28
【问题描述】:
const userSchema = new mongoose.Schema({
email: { type: String, unique: true },
password: String,
notifications: [{
notifiId: {type: Schema.Types.ObjectId, ref: 'Notifications' },
viewed: { type: Number, default: 0 }
}],
}));
如何将notifiId 填充到通知中?
我的代码:
User
.findOne({_id: userNotifications.userId})
.populate({path:'notifications', match: {notificationType:
userNotifications.notificationType}, populate: {path: notifiId })
.exec(function(err, user){
if(err || !user){
return callback(1, null);
}
return callback(null, user.notifications)
});
【问题讨论】:
标签: javascript node.js mongodb mongoose