MongoCollection
MongoCollection::__construct
MongoCollection
PHP Manual

# MongoCollection::batchInsert

(PECL mongo >=0.9.0)

MongoCollection::batchInsert — Inserts multiple documents into this collection

### Descrição

public boolean MongoCollection::batchInsert ( array `$a` )

### Parâmetros

`a`

  An array of arrays.

### Valor Retornado

Returns if the arrays were saved.

### Exemplos

Exemplo #1 MongoCollection::batchInsert() example

Batch insertion is a quick way to add many elements to the database at once

`<?php
$batch = array();
for ($i=0; $i<100; $i++) {
$batch[] = array("i" => i);
}
$m = new Mongo();
$c = $m->selectCollection("foo", "bar.baz");
$c->batchInsert($batch);
$cursor = $c->find()->sort(array("i" => 1));
while ($cursor->hasNext()) {
$obj = $cursor->next();
var_dump($obj["i"]);
}
?>`

O exemplo acima irá imprimir algo similar a:

    int(0)
    int(1)
    int(2)
    ...

MongoCollection
MongoCollection::__construct
MongoCollection
PHP Manual