summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/modifier_pop.cpp
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2014-03-10 11:54:01 -0400
committerScott Hernandez <scotthernandez@gmail.com>2014-03-12 11:47:49 -0400
commitd751c80fe2e4a7922129c5ef47a53b29b9eea728 (patch)
treebdd71c4791e285351801b1f6e2c4bd0399f927ce /src/mongo/db/ops/modifier_pop.cpp
parenta950e940c6d2542d72cb4739c10b968270f6b8b5 (diff)
downloadmongo-d751c80fe2e4a7922129c5ef47a53b29b9eea728.tar.gz
SERVER-12846: don't pop nonexistent paths in update
Diffstat (limited to 'src/mongo/db/ops/modifier_pop.cpp')
-rw-r--r--src/mongo/db/ops/modifier_pop.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/mongo/db/ops/modifier_pop.cpp b/src/mongo/db/ops/modifier_pop.cpp
index 10585a29cf5..dada6d66be7 100644
--- a/src/mongo/db/ops/modifier_pop.cpp
+++ b/src/mongo/db/ops/modifier_pop.cpp
@@ -141,27 +141,32 @@ namespace mongo {
&_preparedState->pathFoundElement);
// Check if we didn't find the full path
if (status.isOK()) {
- // If the path exists, we require the target field to be already an
- // array.
- if (_preparedState->pathFoundElement.getType() != Array) {
- mb::Element idElem = mb::findFirstChildNamed(root, "_id");
- return Status(
- ErrorCodes::BadValue,
- str::stream() << "Can only $pop from arrays. {"
- << idElem.toString()
- << "} has the field '"
- << _preparedState->pathFoundElement.getFieldName()
- << "' of non-array type "
- << typeName(_preparedState->pathFoundElement.getType()));
- }
-
- // No children, nothing to do -- not an error state
- if (!_preparedState->pathFoundElement.hasChildren()) {
+ const bool destExists = (_preparedState->pathFoundIndex == (_fieldRef.numParts()-1));
+ if (!destExists) {
execInfo->noOp = true;
} else {
- _preparedState->elementToRemove = _fromTop ?
- _preparedState->pathFoundElement.leftChild() :
- _preparedState->pathFoundElement.rightChild();
+ // If the path exists, we require the target field to be already an
+ // array.
+ if (_preparedState->pathFoundElement.getType() != Array) {
+ mb::Element idElem = mb::findFirstChildNamed(root, "_id");
+ return Status(
+ ErrorCodes::BadValue,
+ str::stream() << "Can only $pop from arrays. {"
+ << idElem.toString()
+ << "} has the field '"
+ << _preparedState->pathFoundElement.getFieldName()
+ << "' of non-array type "
+ << typeName(_preparedState->pathFoundElement.getType()));
+ }
+
+ // No children, nothing to do -- not an error state
+ if (!_preparedState->pathFoundElement.hasChildren()) {
+ execInfo->noOp = true;
+ } else {
+ _preparedState->elementToRemove = _fromTop ?
+ _preparedState->pathFoundElement.leftChild() :
+ _preparedState->pathFoundElement.rightChild();
+ }
}
} else {
// Let the caller know we can't do anything given the mod, _fieldRef, and doc.