/** * @param string $name Index name * @param array $fields Index fields * @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, array $fields, $sparse = false, $unique = false, $dropDuplicates = false, $language = 'english') { $this->language = $language; 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, 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($field)]); } parent::__construct($name, $fields, $sparse, $unique, $dropDuplicates); }