diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/pipeline/variables.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/pipeline/variables.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/variables.cpp | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/mongo/db/pipeline/variables.cpp b/src/mongo/db/pipeline/variables.cpp index 279b8630ce6..26793962efd 100644 --- a/src/mongo/db/pipeline/variables.cpp +++ b/src/mongo/db/pipeline/variables.cpp @@ -40,21 +40,6 @@ namespace mongo { -namespace { - -// We need to be careful when serializing values, e.g. to populate the 'let' parameter of a command -// to be sent over the wire. First, missing values should be serialied as $$REMOVE, otherwise they -// might be incorrectly omitted or serialized as empty objects ({}). Also, we should wrap values in -// $literal to avoid a scenario like the following: suppose we had a user-defined 'let' specified as -// {let: {a: {$literal: "$notAFieldName"}}}. On mongos, this will be evaluated to the string -// "$notAFieldName". When we serialize it again for the shard commands, it must appear as {$literal: -// "$notAFieldName"}, not simply "$notAFieldName", since the latter will be treated as a field name -// by mongods. -Value serializeValue(Value val) { - return val.missing() ? Value("$$REMOVE"_sd) : Value(DOC("$literal" << val)); -} -} // namespace - using namespace std::string_literals; constexpr Variables::Id Variables::kRootId; @@ -345,8 +330,7 @@ LegacyRuntimeConstants Variables::transitionalExtractRuntimeConstants() const { } Variables::Id VariablesParseState::defineVariable(StringData name) { - // Caller should have validated before hand by using - // variableValidation::validateNameForUserWrite. + // Caller should have validated before hand by using variableValidationvalidateNameForUserWrite. massert(17275, "Can't redefine a non-user-writable variable", Variables::kBuiltinVarNameToId.find(name) == Variables::kBuiltinVarNameToId.end()); @@ -390,9 +374,8 @@ std::set<Variables::Id> VariablesParseState::getDefinedVariableIDs() const { BSONObj VariablesParseState::serialize(const Variables& vars) const { auto bob = BSONObjBuilder{}; for (auto&& [var_name, id] : _variables) - if (vars.hasValue(id)) { - bob << var_name << serializeValue(vars.getValue(id)); - } + if (vars.hasValue(id)) + bob << var_name << Value(DOC("$literal" << vars.getValue(id))); // System variables have to be added separately since the variable IDs are reserved and not // allocated like normal variables, and so not present in '_variables'. @@ -404,9 +387,8 @@ std::pair<LegacyRuntimeConstants, BSONObj> VariablesParseState::transitionalComp const Variables& vars) const { auto bob = BSONObjBuilder{}; for (auto&& [var_name, id] : _variables) - if (vars.hasValue(id)) { - bob << var_name << serializeValue(vars.getValue(id)); - } + if (vars.hasValue(id)) + bob << var_name << Value(DOC("$literal" << vars.getValue(id))); return {vars.transitionalExtractRuntimeConstants(), bob.obj()}; } |
