Phalcon\Db\Adapter\MongoDB\Operation\CreateIndexes::execute PHP 메소드

execute() 공개 메소드

For servers < 2.6, this will actually perform an insert operation on the database's "system.indexes" collection.
또한 보기: Executable::execute()
public execute ( MongoDB\Driver\Server $server ) : string[]
$server MongoDB\Driver\Server
리턴 string[] The names of the created indexes
    public function execute(Server $server)
    {
        if (Functions::serverSupportsFeature($server, self::$wireVersionForCommand)) {
            $this->executeCommand($server);
        } else {
            $this->executeLegacy($server);
        }
        return array_map(function (IndexInput $index) {
            return (string) $index;
        }, $this->indexes);
    }

Usage Example

예제 #1
0
 /**
  * Create one or more indexes for the collection.
  *
  * Each element in the $indexes array must have a "key" document, which
  * contains fields mapped to an order or type. Other options may follow.
  * For example:
  *
  *     $indexes = [
  *         // Create a unique index on the "username" field
  *         [ 'key' => [ 'username' => 1 ], 'unique' => true ],
  *         // Create a 2dsphere index on the "loc" field with a custom name
  *         [ 'key' => [ 'loc' => '2dsphere' ], 'name' => 'geo' ],
  *     ];
  *
  * If the "name" option is unspecified, a name will be generated from the
  * "key" document.
  *
  * @see http://docs.mongodb.org/manual/reference/command/createIndexes/
  * @see http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/
  *
  * @param array[] $indexes List of index specifications
  *
  * @return string[] The names of the created indexes
  * @throws InvalidArgumentException if an index specification is invalid
  */
 public function createIndexes(array $indexes)
 {
     $operation = new CreateIndexes($this->databaseName, $this->collectionName, $indexes);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }