本文整理汇总了PHP中MongoDB\Driver\Server::executeBulkWrite方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::executeBulkWrite方法的具体用法?PHP Server::executeBulkWrite怎么用?PHP Server::executeBulkWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB\Driver\Server
的用法示例。
在下文中一共展示了Server::executeBulkWrite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return DeleteResult
*/
public function execute(Server $server)
{
$bulk = new Bulk();
$bulk->delete($this->filter, ['limit' => $this->limit]);
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
return new DeleteResult($writeResult);
}
示例2: execute
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return InsertOneResult
*/
public function execute(Server $server)
{
$bulk = new Bulk();
$insertedId = $bulk->insert($this->document);
if ($insertedId === null) {
// TODO: This may be removed if PHPC-382 is implemented
$insertedId = is_array($this->document) ? $this->document['_id'] : $this->document->_id;
}
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
return new InsertOneResult($writeResult, $insertedId);
}
示例3: execute
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return BulkWriteResult
*/
public function execute(Server $server)
{
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = [];
foreach ($this->operations as $i => $operation) {
$type = key($operation);
$args = current($operation);
switch ($type) {
case self::DELETE_MANY:
case self::DELETE_ONE:
$bulk->delete($args[0], $args[1]);
break;
case self::INSERT_ONE:
$insertedId = $bulk->insert($args[0]);
if ($insertedId !== null) {
$insertedIds[$i] = $insertedId;
} else {
// TODO: This may be removed if PHPC-382 is implemented
$insertedIds[$i] = is_array($args[0]) ? $args[0]['_id'] : $args[0]->_id;
}
break;
case self::REPLACE_ONE:
case self::UPDATE_MANY:
case self::UPDATE_ONE:
$bulk->update($args[0], $args[1], $args[2]);
}
}
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
return new BulkWriteResult($writeResult, $insertedIds);
}
示例4: execute
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return UpdateResult
*/
public function execute(Server $server)
{
$options = array('multi' => $this->options['multi'], 'upsert' => $this->options['upsert']);
$bulk = new Bulk();
$bulk->update($this->filter, $this->update, $options);
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
return new UpdateResult($writeResult);
}
示例5: executeLegacy
/**
* Create one or more indexes for the collection by inserting into the
* "system.indexes" collection (MongoDB <2.6).
*
* @param Server $server
*/
private function executeLegacy(Server $server)
{
$bulk = new Bulk(['ordered' => true]);
foreach ($this->indexes as $index) {
$bulk->insert($index);
}
$server->executeBulkWrite($this->databaseName . '.system.indexes', $bulk, new WriteConcern(1));
}
示例6: execute
/**
* Execute the operation.
*
* @see Executable::execute()
* @param Server $server
* @return InsertManyResult
*/
public function execute(Server $server)
{
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = [];
foreach ($this->documents as $i => $document) {
$insertedId = $bulk->insert($document);
if ($insertedId !== null) {
$insertedIds[$i] = $insertedId;
} else {
// TODO: This may be removed if PHPC-382 is implemented
$insertedIds[$i] = is_array($document) ? $document['_id'] : $document->_id;
}
}
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
return new InsertManyResult($writeResult, $insertedIds);
}
示例7: executeLegacy
/**
* Create one or more indexes for the collection by inserting into the
* "system.indexes" collection (MongoDB <2.6).
*
* @param Server $server
* @param IndexInput[] $indexes
*/
private function executeLegacy(Server $server)
{
$bulk = new Bulk(true);
foreach ($this->indexes as $index) {
$bulk->insert($index);
}
$server->executeBulkWrite($this->databaseName . '.system.indexes', $bulk);
}