PHP Portal » PHP Handbuch » MongoCollection::batchInsert

Werbung

MongoCollection::batchInsert


(PECL mongo >=0.9.0)

MongoCollection::batchInsertInserts multiple documents into this collection

Beschreibung

public boolean MongoCollection::batchInsert ( array $a )

Parameter-Liste

a

An array of arrays.

Rückgabewerte

Returns if the arrays were saved.

Beispiele

Beispiel #1 MongoCollection::batchInsert() example

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

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
$batch = array(); for ($i=0; $i<100; $i++) { $batch[] = array("i" => i); } $m = new Mongo(); $c = $m->foo->bar->baz; $c->batchInsert($batch); $cursor = $c->find()->sort(array("i" => 1)); while ($cursor->hasNext()) { $obj = $cursor->next(); var_dump($obj["i"]); }

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

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