public __construct ( string $name, array $fields, boolean $sparse = false, boolean $unique = false, boolean $dropDuplicates = false ) | ||
$name | string | Index name |
$fields | array | Index fields, ex: title (ascending), -title (descending) |
$sparse | boolean | Is index sparse? |
$unique | boolean | Is index unique? |
$dropDuplicates | boolean | Drop duplicate documents (only if $unique is used) |
/** * @param string $name Index name * @param array $fields Index fields, ex: title (ascending), -title (descending), title => 'text' * @param bool $sparse Is index sparse? * @param bool $unique Is index unique? * @param bool $dropDuplicates Drop duplicate documents (only if $unique is used) * * @throws MongoException */ public function __construct($name, array $fields, $sparse = false, $unique = false, $dropDuplicates = false) { if (count($fields) < 2) { throw new MongoException(MongoException::COMPOUND_INDEX_NOT_ENOUGH_FIELDS); } parent::__construct($name, $fields, $sparse, $unique, $dropDuplicates); }
/** * @param string $name Index name * @param string $field Index field * * @throws \Webiny\Component\Mongo\MongoException */ public function __construct($name, $field) { if (!is_string($field)) { throw new MongoException('Index field must be a string'); } parent::__construct($name, [$field => '2dsphere']); }
/** * @param string $name Index name * @param string $field Index field, ex: title (ascending), -title (descending) * @param bool $sparse Is index sparse? * @param bool $unique Is index unique? * @param bool $dropDuplicates Drop duplicate documents (only if $unique is used) * @param bool $ttl Document TTL (will only work for date and datetime fields) * * @throws \Webiny\Component\Mongo\MongoException */ public function __construct($name, $field, $sparse = false, $unique = false, $dropDuplicates = false, $ttl = false) { $this->ttl = $ttl; $fields = $this->isArray($field) ? $field : [$field]; if (count($fields) > 1) { throw new MongoException(MongoException::SINGLE_INDEX_TOO_MANY_FIELDS, [count($fields)]); } parent::__construct($name, $fields, $sparse, $unique, $dropDuplicates); }
/** * @param string $name Index name * @param string|array $field Index field(s) * @param bool $sparse Is index sparse? * @param bool $unique Is index unique? * @param bool $dropDuplicates Drop duplicate documents (only if $unique is used) * @param string $language Default language * * @throws MongoException */ public function __construct($name, $field, $sparse = false, $unique = false, $dropDuplicates = false, $language = 'english') { $this->language = $language; $fields = $this->isArray($field) ? $field : [$field]; parent::__construct($name, $fields, $sparse, $unique, $dropDuplicates); }