【问题标题】:Mongoose updating documents: updates just the first oneMongoose 更新文档:只更新第一个
【发布时间】:2012-06-22 04:24:27
【问题描述】:

我有一个奇怪的问题。我在使用 mongoose 的 node.js 服务器中执行此查询:Transaction.update({username : user.username}, {$set: { pending : true }} ... 基本上应该在用户名等于user.username 属性pending: true 的所有项目中设置。问题是它只将它设置为它找到的第一个元素。那可能吗?因为我的数据库中总是有 2 个元素,有时一个正在等待处理,有时另一个但不是两个。

谢谢!

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    mongoose/mongodb 的工作方式是,您必须通过 options 参数指定何时允许多次更新:

    Transaction.update({username : user.username}, {$set: { pending : true }}, {multi: true});
    

    【讨论】:

      猜你喜欢
      • 2011-12-07
      • 2015-02-19
      • 1970-01-01
      • 2019-10-05
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多