ArrayFilter in mongoose

我们两清 提交于 2019-12-12 13:33:14

问题


Convert the query into node. In which version arrayfilter work in mongoose or how can run these in node app

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/


回答1:


According to Release Notes for MongoDB 3.6 https://docs.mongodb.com/manual/release-notes/3.6/

(@ Compatible Drivers) to get access to mongodb 3.6 features it is required to use the node driver 3.x.

It seems that the driver is in RC state (as of the time being of this answer). https://github.com/mongodb/node-mongodb-native/releases

And as such, probably, mongoose is still waiting to start using it. https://github.com/Automattic/mongoose/blob/master/package.json

So you have to wait until these things are arranged or of course you can try to wire things up by your self until the official adaptation is done.


-- Update --

Now it works fine.



来源:https://stackoverflow.com/questions/47881328/arrayfilter-in-mongoose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!