Phalcon\Db\Adapter\MongoDB\Operation\InsertOne::execute PHP Метод

execute() публичный Метод

Execute the operation.
См. также: Executable::execute()
public execute ( MongoDB\Driver\Server $server ) : InsertOneResult
$server MongoDB\Driver\Server
Результат Phalcon\Db\Adapter\MongoDB\InsertOneResult
    public function execute(Server $server)
    {
        $options = [];
        if (isset($this->options['bypassDocumentValidation']) && Functions::serverSupportsFeature($server, self::$wireVersionForDocumentLevelValidation)) {
            $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
        }
        $bulk = new Bulk($options);
        $insertedId = $bulk->insert($this->document);
        if ($insertedId === null) {
            $insertedId = Functions::extractIdFromInsertedDocument($this->document);
        }
        $writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
        $writeResult = $server->executeBulkWrite($this->databaseName . '.' . $this->collectionName, $bulk, $writeConcern);
        return new InsertOneResult($writeResult, $insertedId);
    }

Usage Example

Пример #1
0
 /**
  * Inserts one document.
  *
  * @see InsertOne::__construct() for supported options
  * @see http://docs.mongodb.org/manual/reference/command/insert/
  *
  * @param array|object $document The document to insert
  * @param array        $options Command options
  *
  * @return InsertOneResult
  */
 public function insertOne($document, array $options = [])
 {
     if (!isset($options['writeConcern'])) {
         $options['writeConcern'] = $this->writeConcern;
     }
     $operation = new InsertOne($this->databaseName, $this->collectionName, $document, $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }