这是我的猫鼬图式
pip
填充包含多个ID的bookInfo数组后的输出
const bookModel = new schema({
bookInfo: {
bookedUser: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "UserInfo"
},
username: String
},
date: String,
machineryName: String,
phoneNo: String,
address: String,
Acre: String,
decision: Boolean,
acceptedDriver: {
id: { type: mongoose.Schema.Types.ObjectId, ref: "DriverInfo" },
username: String
}
}
});
module.exports = mongoose.model("bookInfo", bookModel);
此代码一直填充到bookInfo,但是我希望要填充包括id字段的bookInfo。如何在猫鼬中填充嵌套对象
答案 0 :(得分:0)
尝试一下
Comment.find({ parentId: req.params.id})
.then(comments => {
comments.map((comment) => {
// Set the appropriate value.
comment.parentDeleted = true;
// Then save it.
// You can modify what is returned, if needed.
return comment.save();
})
})