| 963 | } |
| 964 | |
| 965 | std::vector<std::string> staticValidateUpdateObject(bson::BSONObj update, bool multi, bool upsert) { |
| 966 | std::set<std::string> affectedFields; |
| 967 | std::set<std::string> prefixesOfAffectedFields; |
| 968 | for (auto i = update.begin(); i.more();) { |
| 969 | |
| 970 | auto el = i.next(); |
| 971 | std::string operatorName = el.fieldName(); |
| 972 | if (!el.isABSONObj() || el.Obj().nFields() == 0) { |
| 973 | throw update_operator_empty_parameter(); |
| 974 | } |
| 975 | |
| 976 | if (upsert && operatorName == DocLayerConstants::SET_ON_INSERT) |
| 977 | operatorName = DocLayerConstants::SET; |
| 978 | |
| 979 | for (auto j = el.Obj().begin(); j.more();) { |
| 980 | bson::BSONElement subel = j.next(); |
| 981 | auto fn = std::string(subel.fieldName()); |
| 982 | if (fn == DocLayerConstants::ID_FIELD) { |
| 983 | if (operatorName != DocLayerConstants::SET && operatorName != DocLayerConstants::SET_ON_INSERT) { |
| 984 | throw cant_modify_id(); |
| 985 | } |
| 986 | } |
| 987 | staticValidateModifiedFields(fn, &affectedFields, &prefixesOfAffectedFields); |
| 988 | if (operatorName == DocLayerConstants::RENAME) { |
| 989 | if (!subel.isString()) |
| 990 | throw bad_rename_target(); |
| 991 | staticValidateModifiedFields(subel.String(), &affectedFields, &prefixesOfAffectedFields); |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | std::vector<std::string> bannedIndexFields; |
| 997 | bannedIndexFields.insert(std::end(bannedIndexFields), std::begin(affectedFields), std::end(affectedFields)); |
| 998 | bannedIndexFields.insert(std::end(bannedIndexFields), std::begin(prefixesOfAffectedFields), |
| 999 | std::end(prefixesOfAffectedFields)); |
| 1000 | |
| 1001 | return bannedIndexFields; |
| 1002 | } |
| 1003 | |
| 1004 | bool shouldCreateRoot(std::string operatorName) { |
| 1005 | return operatorName == DocLayerConstants::SET || operatorName == DocLayerConstants::INC || |
no test coverage detected