【问题标题】:ArrayFilter in mongoose猫鼬中的ArrayFilter
【发布时间】:2018-06-01 13:19:41
【问题描述】:

将查询转换为节点。 arrayfilter 在哪个版本中可以在 mongoose 中运行,或者如何在节点应用程序中运行它们

db.getCollection('student').update(
    { 
        "_id": ObjectId('5a377d62d21a3025a3c3aa49')
    },
    {
        $set: {
            "examples.$[i].isDeleted": true,
            "examples.$[i].updatedAt": new Date(),
            "updatedAt": new Date()
        }
    },
    {
        arrayFilters: [
            {
                "i._id": { 
                    $in:[
                        ObjectId("5a377d62d21a3025a3c3aa4d"),
                        ObjectId("5a377d62d21a3025a3c3aa4c")
                    ]
                }
            }
        ],
        multi: true
    }
)

https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/

【问题讨论】:

    标签: node.js mongodb mongoose array-filter


    【解决方案1】:

    根据发布 MongoDB 3.6 的说明 https://docs.mongodb.com/manual/release-notes/3.6/

    (@ Compatible Drivers) 要访问 mongodb 3.6 功能,需要使用节点驱动程序 3.x。

    似乎驱动程序处于 RC 状态(截至本答案的时间)https://github.com/mongodb/node-mongodb-native/releases

    因此,mongoose 可能仍在等待开始使用它。 https://github.com/Automattic/mongoose/blob/master/package.json

    所以你必须等到这些东西都安排好了,或者你当然可以尝试自己把东西连接起来,直到正式改编完成。


    -- 更新--

    现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 2019-09-16
      • 2020-07-25
      • 2011-10-14
      • 1970-01-01
      • 2017-10-08
      • 2020-04-24
      • 2012-02-09
      • 1970-01-01
      相关资源
      最近更新 更多