/** * Helper function to check if the current equality match paths conflict with a new path. */ static Status checkEqualityConflicts(const EqualityMatches& equalities, const FieldRef& path) { int parentPathPart = -1; const BSONElement& parentEl = findParentEqualityElement(equalities, path, &parentPathPart); if (parentEl.eoo()) return Status::OK(); string errMsg = "cannot infer query fields to set, "; StringData pathStr = path.dottedField(); StringData prefixStr = path.dottedSubstring(0, parentPathPart); StringData suffixStr = path.dottedSubstring(parentPathPart, path.numParts()); if (suffixStr.size() != 0) errMsg += stream() << "both paths '" << pathStr << "' and '" << prefixStr << "' are matched"; else errMsg += stream() << "path '" << pathStr << "' is matched twice"; return Status(ErrorCodes::NotSingleValueField, errMsg); }
static BSONElement findEqualityElement(const EqualityMatches& equalities, const FieldRef& path) { int parentPathPart; const BSONElement& parentEl = pathsupport::findParentEqualityElement(equalities, path, &parentPathPart); if (parentPathPart == static_cast<int>(path.numParts())) return parentEl; if (parentEl.type() != Object) return BSONElement(); StringData suffixStr = path.dottedSubstring(parentPathPart, path.numParts()); BSONMatchableDocument matchable(parentEl.Obj()); return extractKeyElementFromMatchable(matchable, suffixStr); }