diff options
author | Justin Seyster <justin.seyster@mongodb.com> | 2017-07-17 16:57:23 -0400 |
---|---|---|
committer | Justin Seyster <justin.seyster@mongodb.com> | 2017-07-17 17:00:08 -0400 |
commit | c23a43323ed194013b0d16b6cbbd08d88e6a7c08 (patch) | |
tree | 1c458cfcc7754690ade0165e77eac363e519177b /src/mongo/db/update/pop_node.cpp | |
parent | b86c6bcba36785122e4ad1d228e7a2a8602c40b4 (diff) | |
download | mongo-c23a43323ed194013b0d16b6cbbd08d88e6a7c08.tar.gz |
SERVER-28770 Create PullNode
To support PullNode, this patch adds a CopyableMatchExpression class,
which allows it to store a MatchExpression but still be copyable with
the default copy constructor.
This patch also factors out the viability check in PopNode so that
PullNode can use it as well.
Diffstat (limited to 'src/mongo/db/update/pop_node.cpp')
-rw-r--r-- | src/mongo/db/update/pop_node.cpp | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/src/mongo/db/update/pop_node.cpp b/src/mongo/db/update/pop_node.cpp index a5a94ba3005..4b3f6273db3 100644 --- a/src/mongo/db/update/pop_node.cpp +++ b/src/mongo/db/update/pop_node.cpp @@ -31,8 +31,6 @@ #include "mongo/db/update/pop_node.h" #include "mongo/db/matcher/expression_parser.h" -#include "mongo/db/update/path_support.h" -#include "mongo/util/stringutils.h" namespace mongo { @@ -70,33 +68,13 @@ void PopNode::apply(mutablebson::Element element, } if (!pathToCreate->empty()) { - // There were path components which we could not traverse. If 'element' is a nested object - // which does not contain 'pathToCreate', then this is a no-op (e.g. {$pop: {"a.b.c": 1}} - // for document {a: {b: {}}}). - // - // If the element is an array, but the numeric path does not exist, then this is also a - // no-op (e.g. {$pop: {"a.2.b": 1}} for document {a: [{b: 0}, {b: 1}]}). - // - // Otherwise, this the path contains a blocking leaf or array element, which is an error. - if (element.getType() == BSONType::Object) { - *noop = true; - return; - } - - if (element.getType() == BSONType::Array && - parseUnsignedBase10Integer(pathToCreate->getPart(0))) { - *noop = true; - return; - } - - uasserted(ErrorCodes::PathNotViable, - str::stream() << "Cannot use the part (" << pathToCreate->getPart(0) << ") of (" - << pathTaken->dottedField() - << "." - << pathToCreate->dottedField() - << ") to traverse the element ({" - << element.toString() - << "})"); + // There were path components we could not traverse. We treat this as a no-op, unless it + // would have been impossible to create those elements, which we check with + // checkViability(). + UpdateLeafNode::checkViability(element, *pathToCreate, *pathTaken); + + *noop = true; + return; } invariant(!pathTaken->empty()); |