MCPcopy Create free account
hub / github.com/FoundationDB/fdb-document-layer / staticValidateUpdateObject

Function staticValidateUpdateObject

src/ExtMsg.actor.cpp:965–1002  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

963}
964
965std::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
1004bool shouldCreateRoot(std::string operatorName) {
1005 return operatorName == DocLayerConstants::SET || operatorName == DocLayerConstants::INC ||

Calls 3

beginMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected