使用$ [](所有位置运算符)更新数组中的所有对象将返回错误

时间:2018-04-27 15:02:39

标签: node.js database mongodb mongoose mongodb-query

用户模型有一系列通知,每个通知都有一个"读取"财产(真或假)。我试图更新"阅读"所有这些都是" 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...

我使用猫鼬。有任何想法吗?谢谢!

0 个答案:

没有答案