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

MongoDB\ClientBulkWrite::insertOne()

2.1版本新增

MongoDB\ClientBulkWrite::insertOne()

Specify an insert operation in the bulk write command. This method returns the MongoDB\ClientBulkWrite instance on which it's called.

function insertOne(
array|object $document,
mixed &$id = null
): self
$document : array|object
要插入到集合中的文档。
$id :混合
Captures the document's _id field value to store in an optional output variable.

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

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

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

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

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

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

后退

DeleteOne()

在此页面上