用户模型有一系列通知,每个通知都有一个"读取"财产(真或假)。我试图更新"阅读"所有这些都是" true"。这是我的代码:
db.User.findOneAndUpdate(
{ _id: req.token._id },
{ $set: { "notifications.$[].read" : true } }
)
我得到的错误:
"name": "MongoError",
"message": "cannot use the part (notifications of notifications.$[].read) to traverse the element...
我使用猫鼬。有任何想法吗?谢谢!