|
MongoCollection::batchInsertInserts multiple documents into this collection Description
public mixed MongoCollection::batchInsert
( array
$a
[, array $options = array()
] )Parameters
Return Values
If the w parameter is set to acknowledge the write,
returns an associative array with the status of the inserts ("ok") and any
error that may have occurred ("err"). Otherwise, returns Errors/ExceptionsThrows MongoException if any inserted documents are empty or if they contains zero-length keys. Attempting to insert an object with protected and private properties will cause a zero-length key error. Throws MongoCursorException if the "w" option is set and the write fails. Throws MongoCursorTimeoutException if the "w" option is set to a value greater than one and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout. The operation in MongoCollection::$wtimeout is milliseconds. Changelog
ExamplesExample #1 MongoCollection::batchInsert example Batch insertion is a quick way to add many elements to the database at once
<?php The above example will output something similar to: 4bf43ac68ead0e1971000000 4bf43ac68ead0e1971010000 4bf43ac68ead0e1971020000 ... string(5) "user1" string(5) "user2" string(5) "user3" ... Example #2 MongoCollection::batchInsert example with ignoring errors
<?php The above example will output something similar to: string(3) "ONE" string(3) "TWO" string(4) "FOUR" See Also
|