Description描述
Bulk.find.arrayFilters(<array of filter documents>)Determines which array elements to modify for an update operation on an array field:确定在数组字段上进行更新操作时要修改哪些数组元素:Bulk.find(<query>).arrayFilters([ <filter1>, ... ]).updateOne(<update>);
Bulk.find(<query>).arrayFilters([ <filter1>, ... ]).update(<update>);In the update document, use the在更新文档中,使用$[<identifier>]filtered positional operator to define an identifier, which you then reference in the array filter documents.$[<identifier>]筛选位置运算符定义一个标识符,然后在数组筛选文档中引用该标识符。You cannot have an array filter document for an identifier if the identifier is not included in the update document.如果标识符未包含在更新文档中,则无法为标识符创建数组筛选器文档。The<identifier>must begin with a lowercase letter and contain only alphanumeric characters.<identifier>必须以小写字母开头,并且只能包含字母数字字符。You can include the same identifier multiple times in the update document; however, for each distinct identifier (您可以在更新文档中多次包含相同的标识符;但是,对于更新文档中的每个不同标识符($[identifier]) in the update document, you must specify exactly one corresponding array filter document.$[identifier]),您必须指定一个相应的数组筛选器文档。That is, you cannot specify multiple array filter documents for the same identifier. For example, if the update statement includes the identifier也就是说,不能为同一标识符指定多个数组筛选器文档。例如,如果更新语句包含标识符x(possibly multiple times), you cannot specify the following forarrayFiltersthat includes 2 separate filter documents forx:x(可能多次),则不能为包含2个单独的x筛选文档的arrayFilters指定以下内容:// INVALID
[
{ "x.a": { $gt: 85 } },
{ "x.b": { $gt: 80 } }
]However, you can specify compound conditions on the same identifier in a single filter document, such as in the following examples:但是,您可以在单个筛选器文档中为同一标识符指定复合条件,例如以下示例:// Example 1
[
{ $or: [{"x.a": {$gt: 85}}, {"x.b": {$gt: 80}}] }
]
// Example 2
[
{ $and: [{"x.a": {$gt: 85}}, {"x.b": {$gt: 80}}] }
]
// Example 3
[
{ "x.a": { $gt: 85 }, "x.b": { $gt: 80 } }
]Append to附加到Bulk.find()method to specify the array filters for theupdateOne()andupdate()operations.Bulk.find()方法,为updateOne()和update()操作指定数组筛选器。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
Example示例
var bulk = db.coll.initializeUnorderedBulkOp();
bulk.find({}).arrayFilters( [ { "elem.grade": { $gt: 85 } } ] ).updateOne( { $set: { "grades.$[elem].mean" : 70 } } );
bulk.execute();