Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mongowritebatch(3) [php man page]

MONGOWRITEBATCH(3)							 1							MONGOWRITEBATCH(3)

The MongoWriteBatch class

INTRODUCTION
MongoWriteBatch 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 discour- aged. 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. CLASS SYNOPSIS
MongoWriteBatch MongoWriteBatch Constants o const int$MongoWriteBatch::COMMAND_INSERT1 o const int$MongoWriteBatch::COMMAND_UPDATE2 o const int$MongoWriteBatch::COMMAND_DELETE3 Methods o protected MongoWriteBatch::__construct (MongoCollection $collection, [string $batch_type], [array $write_options]) o public bool MongoWriteBatch::add (array $item) o finalpublic array MongoWriteBatch::execute (array $write_options) MONGOWRITEBATCH TYPES
o MongoWriteBatch::COMMAND_INSERT -Create an Insert Write Batch o MongoWriteBatch::COMMAND_UPDATE -Create an Update Write Batch o MongoWriteBatch::COMMAND_DELETE -Create an Delete Write Batch DESCRIPTION
When executing a batch, by calling MongoWriteBatch::execute, MongoWriteBatch will send over maxWriteBatchSize (defaults to 1000) documents or up to maxBsonObjectSize (defaults to 16777216 bytes), whichever comes first. Note Documents will never be partially transferred. When adding documents to the batch, that overflows the limit, a new batch will be created and the document put into the new batch. ERRORS
/EXCEPTIONS oException on parameter parsing failures oException on argument validation errors (e.g. missing keys) oMongoProtocolException when talking to MongoDB server older then 2.6.0. oMongoProtocolException on socket errors. oMongoWriteConcernException when a write fails due to WriteConcerns EXAMPLES
Example #1 MongoWriteBatch example Adding documents to a Insert batch and then execute it <?php $mc = new MongoClient("localhost"); $collection = $mc->selectCollection("test", "test"); $docs = array(); $docs[] = array("my" => "demo"); $docs[] = array("is" => "working"); $docs[] = array("pretty" => "well"); $batch = new MongoInsertBatch($collection); foreach($docs as $document) { $batch->add($document); } $retval = $batch->execute(array("w" => 1)); var_dump($retval); ?> The above example will output: array(2) { ["nInserted"]=> int(3) ["ok"]=> bool(true) } PHP Documentation Group MONGOWRITEBATCH(3)

Check Out this Related Man Page

MONGOCLIENT(3)								 1							    MONGOCLIENT(3)

The MongoClient class

INTRODUCTION
A connection manager for PHP and MongoDB. This class is used to create and manage connections. A typical use is: Example #1 MongoClient basic usage <?php $m = new MongoClient(); // connect $db = $m->foo; // get the database named "foo" ?> See MongoClient.__construct(3) and the section on connecting for more information about creating connections. CLASS SYNOPSIS
MongoClient MongoClient Constants o const string$MongoClient::VERSION o const string$MongoClient::DEFAULT_HOST"localhost" o const int$MongoClient::DEFAULT_PORT27017 o const string$MongoClient::RP_PRIMARY"primary" o const string$MongoClient::RP_PRIMARY_PREFERRED"primaryPreferred" o const string$MongoClient::RP_SECONDARY"secondary" o const string$MongoClient::RP_SECONDARY_PREFERRED"secondaryPreferred" o const string$MongoClient::RP_NEAREST"nearest" Properties o public boolean$connected FALSE o public string$status NULL o protected string$server NULL o protected boolean$persistent NULL Methods o public MongoClient::__construct TRUE ([string $server = "mongodb://localhost:27017"], [array $options = )], [array $driver_options]) o public bool MongoClient::close ([boolean|string $connection]) o public bool MongoClient::connect (void ) o public array MongoClient::dropDB (mixed $db) o public MongoDB MongoClient::__get (string $dbname) o publicstatic array MongoClient::getConnections (void ) o public array MongoClient::getHosts (void ) o public array MongoClient::getReadPreference (void ) o public array MongoClient::getWriteConcern (void ) o public bool MongoClient::killCursor (string $server_hash, int|MongoInt64 $id) o public array MongoClient::listDBs (void ) o public MongoCollection MongoClient::selectCollection (string $db, string $collection) o public MongoDB MongoClient::selectDB (string $name) o public bool MongoClient::setReadPreference (string $read_preference, [array $tags]) o public bool MongoClient::setWriteConcern (mixed $w, [int $wtimeout]) o public string MongoClient::__toString (void ) PREDEFINED CONSTANTS
MONGOCLIENT CONSTANTS
o MongoClient::VERSION - PHP driver version. May be suffixed with "dev", "+" or "-" if it is in-between versions. o MongoClient::DEFAULT_HOST - "localhost" - Host to connect to if no host is given. o MongoClient::DEFAULT_PORT - 27017 - Port to connect to if no port is given. o MongoClient::RP_PRIMARY - "primary" -Read preference for the primary replica set member. o MongoClient::RP_PRIMARY_PREFERRED - "primaryPreferred" -Read preference for preferring the primary replica set member. o MongoClient::RP_SECONDARY - "secondary" -Read preference for a secondary replica set member. o MongoClient::RP_SECONDARY_PREFERRED - "secondaryPreferred" -Read preference for preferring a secondary replica set member. o MongoClient::RP_NEAREST - "nearest" -Read preference for the nearest replica set member. FIELDS
o $connected - This property will be set to TRUE if we have a open connection to the database, FALSE otherwise. If the connection is to a replica set, this property will only be TRUE if the driver has a connection to a node matching the current read preference. This property does not take authentication into account. This property is deprecated since version 1.5.0. o $status - This property is no longer used and will be set to NULL In driver versions 1.1.x and earlier, this may be set to a string value (e.g. "recycled", "new") when persistent connections are used. This property is deprecated since version 1.5.0. SEE ALSO
o"Read Preferences" o"Write Concerns" o"Connecting" oMongoDB core docs on connecting PHP Documentation Group MONGOCLIENT(3)
Man Page