public batchInsert ( string $collectionName, array[] $documents, array $options = [] ) : array | false | ||
$collectionName | string | collection name |
$documents | array[] | documents list |
$options | array | list of options in format: optionName => optionValue. |
return | array | false | list of inserted IDs, `false` on failure. |
public function batchInsert($collectionName, $documents, $options = [])
{
$this->document = [];
foreach ($documents as $key => $document) {
$this->document[$key] = ['type' => 'insert', 'document' => $document];
}
$result = $this->executeBatch($collectionName, $options);
if ($result['result']->getInsertedCount() < 1) {
return false;
}
return $result['insertedIds'];
}