bool IndexDescriptor::areIndexOptionsEquivalent(const IndexDescriptor* other) const { if (isSparse() != other->isSparse()) { return false; } if (!isIdIndex() && unique() != other->unique()) { // Note: { _id: 1 } or { _id: -1 } implies unique: true. return false; } // Then compare the rest of the options. std::map<StringData, BSONElement> existingOptionsMap; populateOptionsMap(existingOptionsMap, infoObj()); std::map<StringData, BSONElement> newOptionsMap; populateOptionsMap(newOptionsMap, other->infoObj()); return existingOptionsMap.size() == newOptionsMap.size() && std::equal(existingOptionsMap.begin(), existingOptionsMap.end(), newOptionsMap.begin(), [](const std::pair<StringData, BSONElement>& lhs, const std::pair<StringData, BSONElement>& rhs) { return lhs.first == rhs.first && SimpleBSONElementComparator::kInstance.evaluate(lhs.second == rhs.second); }); }
bool IndexDescriptor::areIndexOptionsEquivalent( const IndexDescriptor* other ) const { if ( isSparse() != other->isSparse() ) { return false; } if ( !isIdIndex() && unique() != other->unique() ) { // Note: { _id: 1 } or { _id: -1 } implies unique: true. return false; } // Then compare the rest of the options. std::map<StringData, BSONElement> existingOptionsMap; populateOptionsMap( existingOptionsMap, infoObj() ); std::map<StringData, BSONElement> newOptionsMap; populateOptionsMap( newOptionsMap, other->infoObj() ); return existingOptionsMap == newOptionsMap; }