问题
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