Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Docs 菜单
Docs 主页
/ / /
PHP 库手册
/ /

MongoDB\ClientBulkWrite::updateMany()

2.1版本新增

MongoDB\ClientBulkWrite::updateMany()

Specify an update operation in the bulk write command for all matching documents. This method returns the MongoDB\ClientBulkWrite instance on which it's called.

function updateMany(
array|object $filter,
array|object $update,
array $options = []
): self
$filter : array|object
指定要更新的文档的筛选条件。
$update : array|object
The field and value combinations to update and any relevant update operators. $update uses MongoDB's update operators. You can pass an aggregation pipeline as this parameter.
$options : array

指定所需选项的数组。

名称
类型
说明

名称

类型

说明

arrayFilters

阵列

一个筛选器文档数组,确定要针对数组字段的更新操作修改哪些数组元素。

排序规则

数组|对象

排序规则允许用户为string比较指定特定于语言的规则,例如字母大小写和重音符号规则。 指定排序规则时, locale字段为必填字段;所有其他排序规则字段都是可选的。 有关字段的说明,请参阅排序规则文档。

如果未指定排序规则但集合具有默认排序规则,则操作将使用为集合指定的排序规则。如果没有为集合或操作指定排序规则,MongoDB 将使用先前版本中用于字符串比较的简单二进制比较。

提示

字符串|数组|对象

要使用的索引。将索引名称指定为字符串或将索引键模式指定为文档。如果指定,查询系统将只考虑使用提示索引的计划。

更新插入

布尔

如果设置为 true,则在没有文档符合查询条件时创建一个新文档。默认值为 false,在未找到匹配项时不插入新文档。

MongoDB\Exception\UnsupportedException,如果所选服务器使用了选项但不支持选项(例如collationreadConcernwriteConcern)。

MongoDB\Exception\InvalidArgumentException 用于与参数或选项解析相关的错误。

MongoDB\ 驱动程序\Exception\BulkWriteCommandException 以了解与写入操作相关的错误。您可以检查 getWriteErrors() 返回的值,以确定错误的性质。

MongoDB\ 驱动程序\Exception\RuntimeException 对于扩展级别的其他错误(例如连接错误)。

在评估查询条件时,MongoDB 会根据自己 的 比较规则来BSON types 比较类型和值,这不同于 的PHP 比较 类型杂技 规则。匹配特殊BSON类型时,查询条件应使用相应的 BSON类 在扩展(例如使用 MongoDB\ BSON\ObjectId 以匹配 ObjectId )。

如果引发MongoDB\ 驱动程序\Exception\BulkWriteCommandException,您可以调用 getWriteErrors() 并检查返回大量中的信息,以确定错误的性质。

示例,写入操作可能已成功应用于主节点 (primary node in the replica set)服务器,但未能满足写关注(write concern)。或者,写入操作可能彻底失败,示例由于违反了唯一键约束。

  • 批量写入操作指南的客户端批量写入部分

后退

replaceOne()

在此页面上