MongoDB\ClientBulkWrite::createWithCollection()
2.1版本新增。
定义
MongoDB\ClientBulkWrite::createWithCollection()
Create an instance of the
MongoDB\ClientBulkWrite
builder from the providedMongoDB\Collection
instance. You can add write operations to theClientBulkWrite
to create a new BulkWriteCommand that the library sends to the server.function createWithCollection( Collection $collection, array $options = [] ): self
参数
$collection
:MongoDB\Collection
- The
Collection
instance to set as the target for bulk write operations. $options
: array指定所需选项的数组。
名称类型说明bypassDocumentValidation
布尔
If
true
: the write operation ignores document level validation.默认为
false
。comment
混合
let
数组|对象
参数名称和值的映射。值必须是常量或不引用文档字段的封闭表达式。然后可以在聚合表达式上下文中将参数作为变量进行访问(例如
$$var
)。MongoDB 服务器 6.0 及更早版本不支持此功能。如果使用,服务器将在执行时返回异常。
ordered
布尔
If
true
: When a single write fails, the operation stops without performing the remaining writes and throws an exception.If
false
: When a single write fails, the operation continues with the remaining writes, if any, and throws an exception.默认为
true
。verboseResults
布尔
Specifies whether to return verbose results.
默认为
false
。
Return Values
A new ClientBulkWrite
instance with an empty BulkWriteCommand
specification.
错误/异常
MongoDB\Exception\UnsupportedException
,如果所选服务器使用了选项但不支持选项(例如collation
、readConcern
、writeConcern
)。
MongoDB\Exception\InvalidArgumentException
用于与参数或选项解析相关的错误。
MongoDB\ 驱动程序\Exception\RuntimeException 对于扩展级别的其他错误(例如连接错误)。