我正在尝试将Mongoose findByIdAndUpdate函数与引用用户ID的子文档架构一起使用。好吧,它看起来像这样:
评论架构
var commentSchema = mongoose.Schema({
text: String,
createdAt: {type: Date, default: Date.now},
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String,
avatar: String
}
});
我想查找具有该功能的特定用户的评论
router.put("/:id", middleware.isLoggedIn, function(req, res){
Comment.findByIdAndUpdate({author: {id:req.params.id}}, {$set: {text: "Test"}}, {new: true}, function(err, updatedComment){
if(err){
console.log("ERROR!");
} else {
console.log(updatedComment);
}
});
但是输出信息始终为“ ERROR” 请帮助!!!