Doctrine\ODM\MongoDB\SchemaManager::isMongoIndexEquivalentToDocumentIndex PHP Метод

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

Indexes are considered different if: (a) Key/direction pairs differ or are not in the same order (b) Sparse or unique options differ (c) Mongo index is unique without dropDups and mapped index is unique with dropDups (d) Geospatial options differ (bits, max, min) (e) The partialFilterExpression differs Regarding (c), the inverse case is not a reason to delete and recreate the index, since dropDups only affects creation of the unique index. Additionally, the background option is only relevant to index creation and is not considered.
public isMongoIndexEquivalentToDocumentIndex ( array $mongoIndex, array $documentIndex ) : boolean
$mongoIndex array Mongo index data.
$documentIndex array Document index data.
Результат boolean True if the indexes are equivalent, otherwise false.
    public function isMongoIndexEquivalentToDocumentIndex($mongoIndex, $documentIndex)
    {
        $documentIndexOptions = $documentIndex['options'];
        if ($mongoIndex['key'] != $documentIndex['keys']) {
            return false;
        }
        if (empty($mongoIndex['sparse']) xor empty($documentIndexOptions['sparse'])) {
            return false;
        }
        if (empty($mongoIndex['unique']) xor empty($documentIndexOptions['unique'])) {
            return false;
        }
        if (!empty($mongoIndex['unique']) && empty($mongoIndex['dropDups']) && !empty($documentIndexOptions['unique']) && !empty($documentIndexOptions['dropDups'])) {
            return false;
        }
        foreach (array('bits', 'max', 'min') as $option) {
            if (isset($mongoIndex[$option]) xor isset($documentIndexOptions[$option])) {
                return false;
            }
            if (isset($mongoIndex[$option]) && isset($documentIndexOptions[$option]) && $mongoIndex[$option] !== $documentIndexOptions[$option]) {
                return false;
            }
        }
        if (empty($mongoIndex['partialFilterExpression']) xor empty($documentIndexOptions['partialFilterExpression'])) {
            return false;
        }
        if (isset($mongoIndex['partialFilterExpression']) && isset($documentIndexOptions['partialFilterExpression']) && $mongoIndex['partialFilterExpression'] !== $documentIndexOptions['partialFilterExpression']) {
            return false;
        }
        return true;
    }