/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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)); }
/** * 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); }
/** * 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); }