(mongodb >=1.0.0)
MongoDB\Driver\BulkWrite::insert — 向批量添加插入操作
向 MongoDB\Driver\BulkWrite 添加插入操作。
返回插入文档的 _id
。如果 document
没有 _id
,则将返回为插入生成的 MongoDB\BSON\ObjectId。
范例 #1 MongoDB\Driver\BulkWrite::insert() 示例
<?php
$bulk = new MongoDB\Driver\BulkWrite;
$document1 = ['title' => 'one'];
$document2 = ['_id' => 'custom ID', 'title' => 'two'];
$document3 = ['_id' => new MongoDB\BSON\ObjectId, 'title' => 'three'];
$_id1 = $bulk->insert($document1);
$_id2 = $bulk->insert($document2);
$_id3 = $bulk->insert($document3);
var_dump($_id1, $_id2, $_id3);
$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$result = $manager->executeBulkWrite('db.collection', $bulk);
?>
上面的示例将输出类似于以下内容
object(MongoDB\BSON\ObjectId)#3 (1) { ["oid"]=> string(24) "54d51146bd21b91405401d92" } NULL NULL