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)
});
答案 0 :(得分:1)
尝试:
notifications: {
notifiId: {type: Schema.Types.ObjectId, ref: 'Notifications' },
viewed: { type: Number, default: 0 }
},
并找到它:
model_Variable.findById(req.params.id).populate("notifiId").exec(function (err,
callBack) {});