Batch ClassesInhaltsverzeichnis
The MongoWriteBatch classEinführungMongoWriteBatch is the base class for the MongoInsertBatch, MongoUpdateBatch and MongoDeleteBatch classes. MongoWriteBatch allows you to "batch up" multiple operations (of same type) and shipping them all to MongoDB at the same time. This can be especially useful when operating on many documents at the same time to reduce roundtrips. Prior to version 1.5.0 of the driver it was possible to use MongoCollection::batchInsert, however, as of 1.5.0 that method is now discouraged. Note: This class is only available when talking to MongoDB 2.6.0 (and later) servers. It will throw MongoProtocolException if attempting to use it on older MongoDB servers. KlassenbeschreibungMongoWriteBatch
class MongoWriteBatch
{
/* Konstanten */
const
int
MongoWriteBatch::COMMAND_INSERT
= 1
;
const
int
MongoWriteBatch::COMMAND_UPDATE
= 2
;
const
int
MongoWriteBatch::COMMAND_DELETE
= 3
;
/* Methoden */
protected __construct
( MongoCollection
$collection
[, string $batch_type
[, array $write_options
]] )
public bool add
( array
$item
)
final public array execute
( array
}$write_options
)MongoWriteBatch types
BeschreibungWhen executing a batch by calling MongoWriteBatch::execute, MongoWriteBatch will send up to maxWriteBatchSize (defaults to 1000) documents or maxBsonObjectSize (defaults to 16777216 bytes), whichever comes first.
Fehler/Exceptions
BeispieleBeispiel #1 MongoWriteBatch example Adding documents to a Insert batch and then execute it
<?phpDas oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(2) {
["nInserted"]=>
int(3)
["ok"]=>
bool(true)
}
The MongoInsertBatch classEinführungConstructs a batch of INSERT operations. See MongoWriteBatch. KlassenbeschreibungMongoInsertBatch
class MongoInsertBatch
extends
MongoWriteBatch
{
/* Methoden */
public __construct
( MongoCollection
$collection
[, array $write_options
] )/* Geerbte Methoden */
public bool MongoWriteBatch::add
( array
$item
)
final public array MongoWriteBatch::execute
( array
}$write_options
)The MongoUpdateBatch classEinführungConstructs a batch of UPDATE operations. See MongoWriteBatch. KlassenbeschreibungMongoUpdateBatch
class MongoUpdateBatch
extends
MongoWriteBatch
{
/* Methoden */
public __construct
( MongoCollection
$collection
[, array $write_options
] )/* Geerbte Methoden */
public bool MongoWriteBatch::add
( array
$item
)
final public array MongoWriteBatch::execute
( array
}$write_options
)The MongoDeleteBatch classEinführungConstructs a batch of DELETE operations. See MongoWriteBatch. KlassenbeschreibungMongoDeleteBatch
class MongoDeleteBatch
extends
MongoWriteBatch
{
/* Methoden */
public __construct
( MongoCollection
$collection
[, array $write_options
] )/* Geerbte Methoden */
public bool MongoWriteBatch::add
( array
$item
)
final public array MongoWriteBatch::execute
( array
}$write_options
) |