summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/modifier_compare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/ops/modifier_compare.cpp')
-rw-r--r--src/mongo/db/ops/modifier_compare.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mongo/db/ops/modifier_compare.cpp b/src/mongo/db/ops/modifier_compare.cpp
index 2c9a48ac238..3be7c669428 100644
--- a/src/mongo/db/ops/modifier_compare.cpp
+++ b/src/mongo/db/ops/modifier_compare.cpp
@@ -107,6 +107,8 @@ Status ModifierCompare::prepare(mutablebson::Element root,
// be created during the apply.
Status status = pathsupport::findLongestPrefix(
_updatePath, root, &_preparedState->idxFound, &_preparedState->elemFound);
+ const auto elemFoundIsArray =
+ _preparedState->elemFound.ok() && _preparedState->elemFound.getType() == BSONType::Array;
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
@@ -125,6 +127,11 @@ Status ModifierCompare::prepare(mutablebson::Element root,
_preparedState->idxFound == (_updatePath.numParts() - 1));
if (!destExists) {
execInfo->noOp = false;
+
+ if (elemFoundIsArray) {
+ // Report that an existing array will gain a new element as a result of this mod.
+ execInfo->indexOfArrayWithNewElement[0] = _preparedState->idxFound;
+ }
} else {
const int compareVal = _preparedState->elemFound.compareWithBSONElement(_val, false);
execInfo->noOp = (compareVal == 0) ||