diff options
Diffstat (limited to 'src/mongo/db/update')
34 files changed, 93 insertions, 163 deletions
diff --git a/src/mongo/db/update/addtoset_node.cpp b/src/mongo/db/update/addtoset_node.cpp index 4805ae5c825..b12c4ceeb9b 100644 --- a/src/mongo/db/update/addtoset_node.cpp +++ b/src/mongo/db/update/addtoset_node.cpp @@ -108,8 +108,7 @@ ModifierNode::ModifyResult AddToSetNode::updateExistingElement( mutablebson::Element* element, std::shared_ptr<FieldRef> elementPath) const { uassert(ErrorCodes::BadValue, str::stream() << "Cannot apply $addToSet to non-array field. Field named '" - << element->getFieldName() - << "' has non-array type " + << element->getFieldName() << "' has non-array type " << typeName(element->getType()), element->getType() == BSONType::Array); diff --git a/src/mongo/db/update/addtoset_node_test.cpp b/src/mongo/db/update/addtoset_node_test.cpp index 9c3bfc283a5..0aaf434fcdb 100644 --- a/src/mongo/db/update/addtoset_node_test.cpp +++ b/src/mongo/db/update/addtoset_node_test.cpp @@ -44,8 +44,8 @@ namespace mongo { namespace { using AddToSetNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; DEATH_TEST(AddToSetNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { auto update = fromjson("{$addToSet: {}}"); diff --git a/src/mongo/db/update/arithmetic_node.cpp b/src/mongo/db/update/arithmetic_node.cpp index 304b0261e90..58c0d4a27ab 100644 --- a/src/mongo/db/update/arithmetic_node.cpp +++ b/src/mongo/db/update/arithmetic_node.cpp @@ -55,9 +55,7 @@ Status ArithmeticNode::init(BSONElement modExpr, if (!modExpr.isNumber()) { return Status(ErrorCodes::TypeMismatch, str::stream() << "Cannot " << getNameForOp(_op) - << " with non-numeric argument: {" - << modExpr - << "}"); + << " with non-numeric argument: {" << modExpr << "}"); } _val = modExpr; @@ -72,10 +70,8 @@ ModifierNode::ModifyResult ArithmeticNode::updateExistingElement( str::stream() << "Cannot apply " << operatorName() << " to a value of non-numeric type. {" << (idElem.ok() ? idElem.toString() : "no id") - << "} has the field '" - << element->getFieldName() - << "' of non-numeric type " - << typeName(element->getType())); + << "} has the field '" << element->getFieldName() + << "' of non-numeric type " << typeName(element->getType())); } SafeNum originalValue = element->getValueSafeNum(); @@ -97,10 +93,8 @@ ModifierNode::ModifyResult ArithmeticNode::updateExistingElement( auto idElem = mutablebson::findFirstChildNamed(element->getDocument().root(), "_id"); uasserted(ErrorCodes::BadValue, str::stream() << "Failed to apply " << operatorName() - << " operations to current value (" - << originalValue.debugString() - << ") for document {" - << (idElem.ok() ? idElem.toString() : "no id") + << " operations to current value (" << originalValue.debugString() + << ") for document {" << (idElem.ok() ? idElem.toString() : "no id") << "}"); } else { invariant(element->setValueSafeNum(valueToSet)); diff --git a/src/mongo/db/update/arithmetic_node_test.cpp b/src/mongo/db/update/arithmetic_node_test.cpp index d18cc4f1314..2783a32d547 100644 --- a/src/mongo/db/update/arithmetic_node_test.cpp +++ b/src/mongo/db/update/arithmetic_node_test.cpp @@ -43,8 +43,8 @@ namespace mongo { namespace { using ArithmeticNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; DEATH_TEST(ArithmeticNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { auto update = fromjson("{$inc: {}}"); diff --git a/src/mongo/db/update/bit_node.cpp b/src/mongo/db/update/bit_node.cpp index 67a334970fc..19f7a560846 100644 --- a/src/mongo/db/update/bit_node.cpp +++ b/src/mongo/db/update/bit_node.cpp @@ -60,9 +60,7 @@ Status BitNode::init(BSONElement modExpr, const boost::intrusive_ptr<ExpressionC return Status(ErrorCodes::BadValue, str::stream() << "The $bit modifier only supports 'and', 'or', and 'xor', not '" - << payloadFieldName - << "' which is an unknown operator: {" - << curOp + << payloadFieldName << "' which is an unknown operator: {" << curOp << "}"); } @@ -70,9 +68,7 @@ Status BitNode::init(BSONElement modExpr, const boost::intrusive_ptr<ExpressionC return Status(ErrorCodes::BadValue, str::stream() << "The $bit modifier field must be an Integer(32/64 bit); a '" - << typeName(curOp.type()) - << "' is not supported here: {" - << curOp + << typeName(curOp.type()) << "' is not supported here: {" << curOp << "}"); } @@ -97,11 +93,8 @@ ModifierNode::ModifyResult BitNode::updateExistingElement( mutablebson::findFirstChildNamed(element->getDocument().root(), "_id"); uasserted(ErrorCodes::BadValue, str::stream() << "Cannot apply $bit to a value of non-integral type." - << idElem.toString() - << " has the field " - << element->getFieldName() - << " of non-integer type " - << typeName(element->getType())); + << idElem.toString() << " has the field " << element->getFieldName() + << " of non-integer type " << typeName(element->getType())); } SafeNum value = applyOpList(element->getValueSafeNum()); diff --git a/src/mongo/db/update/bit_node.h b/src/mongo/db/update/bit_node.h index 07812b3e08a..a2d51dadb4d 100644 --- a/src/mongo/db/update/bit_node.h +++ b/src/mongo/db/update/bit_node.h @@ -72,7 +72,7 @@ private: BSONObjBuilder bob; { BSONObjBuilder subBuilder(bob.subobjStart("")); - for (const auto[bitOperator, operand] : _opList) { + for (const auto [bitOperator, operand] : _opList) { operand.toBSON( [](SafeNum (SafeNum::*bitOperator)(const SafeNum&) const) { if (bitOperator == &SafeNum::bitAnd) diff --git a/src/mongo/db/update/bit_node_test.cpp b/src/mongo/db/update/bit_node_test.cpp index 78734dd63dd..488ad971e5d 100644 --- a/src/mongo/db/update/bit_node_test.cpp +++ b/src/mongo/db/update/bit_node_test.cpp @@ -43,8 +43,8 @@ namespace mongo { namespace { using BitNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST(BitNodeTest, InitWithDoubleFails) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); @@ -292,4 +292,4 @@ TEST_F(BitNodeTest, ApplyRepeatedBitOps) { } } // namespace -} // namepace mongo +} // namespace mongo diff --git a/src/mongo/db/update/compare_node_test.cpp b/src/mongo/db/update/compare_node_test.cpp index b500701cf2d..05c5d9ee68a 100644 --- a/src/mongo/db/update/compare_node_test.cpp +++ b/src/mongo/db/update/compare_node_test.cpp @@ -44,8 +44,8 @@ namespace mongo { namespace { using CompareNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; DEATH_TEST(CompareNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { auto update = fromjson("{$max: {}}"); diff --git a/src/mongo/db/update/current_date_node_test.cpp b/src/mongo/db/update/current_date_node_test.cpp index 7bd11c9140b..e16a2cdbe46 100644 --- a/src/mongo/db/update/current_date_node_test.cpp +++ b/src/mongo/db/update/current_date_node_test.cpp @@ -43,8 +43,8 @@ namespace mongo { namespace { using CurrentDateNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; DEATH_TEST(CurrentDateNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { auto update = fromjson("{$currentDate: {}}"); @@ -286,4 +286,4 @@ TEST_F(CurrentDateNodeTest, ApplyNoIndexDataOrLogBuilder) { } } // namespace -} // namespace +} // namespace mongo diff --git a/src/mongo/db/update/field_checker_test.cpp b/src/mongo/db/update/field_checker_test.cpp index 99deff9fb07..d95b2bc681f 100644 --- a/src/mongo/db/update/field_checker_test.cpp +++ b/src/mongo/db/update/field_checker_test.cpp @@ -38,9 +38,9 @@ namespace { using mongo::ErrorCodes; using mongo::FieldRef; -using mongo::fieldchecker::isUpdatable; -using mongo::fieldchecker::isPositional; using mongo::Status; +using mongo::fieldchecker::isPositional; +using mongo::fieldchecker::isUpdatable; TEST(IsUpdatable, Basics) { FieldRef fieldRef("x"); diff --git a/src/mongo/db/update/log_builder.cpp b/src/mongo/db/update/log_builder.cpp index e78cd295b1f..5fbd6514791 100644 --- a/src/mongo/db/update/log_builder.cpp +++ b/src/mongo/db/update/log_builder.cpp @@ -89,11 +89,9 @@ Status LogBuilder::addToSetsWithNewFieldName(StringData name, const mutablebson: mutablebson::Element elemToSet = _logRoot.getDocument().makeElementWithNewFieldName(name, val); if (!elemToSet.ok()) return Status(ErrorCodes::InternalError, - str::stream() << "Could not create new '" << name - << "' element from existing element '" - << val.getFieldName() - << "' of type " - << typeName(val.getType())); + str::stream() + << "Could not create new '" << name << "' element from existing element '" + << val.getFieldName() << "' of type " << typeName(val.getType())); return addToSets(elemToSet); } @@ -102,11 +100,9 @@ Status LogBuilder::addToSetsWithNewFieldName(StringData name, const BSONElement& mutablebson::Element elemToSet = _logRoot.getDocument().makeElementWithNewFieldName(name, val); if (!elemToSet.ok()) return Status(ErrorCodes::InternalError, - str::stream() << "Could not create new '" << name - << "' element from existing element '" - << val.fieldName() - << "' of type " - << typeName(val.type())); + str::stream() + << "Could not create new '" << name << "' element from existing element '" + << val.fieldName() << "' of type " << typeName(val.type())); return addToSets(elemToSet); } diff --git a/src/mongo/db/update/modifier_node.cpp b/src/mongo/db/update/modifier_node.cpp index 674a2d8e361..dd0341255a3 100644 --- a/src/mongo/db/update/modifier_node.cpp +++ b/src/mongo/db/update/modifier_node.cpp @@ -66,10 +66,8 @@ void checkImmutablePathsNotModifiedFromOriginal(mutablebson::Element element, if (prefixSize == (*immutablePath)->numParts()) { uasserted(ErrorCodes::ImmutableField, str::stream() << "Updating the path '" << pathTaken->dottedField() << "' to " - << element.toString() - << " would modify the immutable field '" - << (*immutablePath)->dottedField() - << "'"); + << element.toString() << " would modify the immutable field '" + << (*immutablePath)->dottedField() << "'"); } // If 'pathTaken' is a strict prefix of 'immutablePath', then we may have modified @@ -106,8 +104,7 @@ void checkImmutablePathsNotModifiedFromOriginal(mutablebson::Element element, uassert(ErrorCodes::ImmutableField, str::stream() << "After applying the update, the immutable field '" << (*immutablePath)->dottedField() - << "' was found to have been altered to " - << newElem.toString(), + << "' was found to have been altered to " << newElem.toString(), newElem.compareWithBSONElement(oldElem, nullptr, false) == 0); } } @@ -137,8 +134,7 @@ void checkImmutablePathsNotModified(mutablebson::Element element, uassert(ErrorCodes::ImmutableField, str::stream() << "Performing an update on the path '" << pathTaken->dottedField() << "' would modify the immutable field '" - << (*immutablePath)->dottedField() - << "'", + << (*immutablePath)->dottedField() << "'", pathTaken->commonPrefixSize(**immutablePath) < std::min(pathTaken->numParts(), (*immutablePath)->numParts())); } @@ -265,12 +261,10 @@ UpdateExecutor::ApplyResult ModifierNode::applyToNonexistentElement( // because we just created this element.) uassert(ErrorCodes::ImmutableField, str::stream() << "Updating the path '" - << updateNodeApplyParams.pathTaken->dottedField() - << "' to " + << updateNodeApplyParams.pathTaken->dottedField() << "' to " << applyParams.element.toString() << " would modify the immutable field '" - << (*immutablePath)->dottedField() - << "'", + << (*immutablePath)->dottedField() << "'", updateNodeApplyParams.pathTaken->commonPrefixSize(**immutablePath) != (*immutablePath)->numParts()); } diff --git a/src/mongo/db/update/object_replace_executor.cpp b/src/mongo/db/update/object_replace_executor.cpp index 8a65cd1b0ca..31ea35df114 100644 --- a/src/mongo/db/update/object_replace_executor.cpp +++ b/src/mongo/db/update/object_replace_executor.cpp @@ -136,8 +136,7 @@ UpdateExecutor::ApplyResult ObjectReplaceExecutor::applyReplacementUpdate( uassert(ErrorCodes::ImmutableField, str::stream() << "After applying the update, the (immutable) field '" << (*path)->dottedField() - << "' was found to have been altered to " - << newElem.toString(), + << "' was found to have been altered to " << newElem.toString(), newElem.compareWithBSONElement(oldElem, nullptr, false) == 0); } } diff --git a/src/mongo/db/update/object_replace_executor_test.cpp b/src/mongo/db/update/object_replace_executor_test.cpp index cef054fd289..6b0d93f6e46 100644 --- a/src/mongo/db/update/object_replace_executor_test.cpp +++ b/src/mongo/db/update/object_replace_executor_test.cpp @@ -42,8 +42,8 @@ namespace mongo { namespace { using ObjectReplaceExecutorTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST_F(ObjectReplaceExecutorTest, Noop) { auto obj = fromjson("{a: 1, b: 2}"); diff --git a/src/mongo/db/update/path_support.cpp b/src/mongo/db/update/path_support.cpp index 55f369164a8..a419ee2f457 100644 --- a/src/mongo/db/update/path_support.cpp +++ b/src/mongo/db/update/path_support.cpp @@ -53,8 +53,8 @@ Status maybePadTo(mutablebson::Element* elemArray, size_t sizeRequired) { if (toPad > kMaxPaddingAllowed) { return Status(ErrorCodes::CannotBackfillArray, - str::stream() << "can't backfill more than " << kMaxPaddingAllowed - << " elements"); + str::stream() + << "can't backfill more than " << kMaxPaddingAllowed << " elements"); } for (size_t i = 0; i < toPad; i++) { @@ -128,10 +128,8 @@ Status findLongestPrefix(const FieldRef& prefix, *elemFound = prev; return Status(ErrorCodes::PathNotViable, str::stream() << "cannot use the part (" << prefix.getPart(i - 1) << " of " - << prefix.dottedField() - << ") to traverse the element ({" - << curr.toString() - << "})"); + << prefix.dottedField() << ") to traverse the element ({" + << curr.toString() << "})"); } else if (curr.ok()) { *idxFound = i - 1; *elemFound = curr; @@ -153,9 +151,7 @@ StatusWith<mutablebson::Element> createPathAt(const FieldRef& prefix, if (elemFound.getType() != BSONType::Object && elemFound.getType() != BSONType::Array) { return Status(ErrorCodes::PathNotViable, str::stream() << "Cannot create field '" << prefix.getPart(idxFound) - << "' in element {" - << elemFound.toString() - << "}"); + << "' in element {" << elemFound.toString() << "}"); } // Sanity check that 'idxField' is an actual part. @@ -175,9 +171,7 @@ StatusWith<mutablebson::Element> createPathAt(const FieldRef& prefix, if (!newIdx) { return Status(ErrorCodes::PathNotViable, str::stream() << "Cannot create field '" << prefix.getPart(idxFound) - << "' in element {" - << elemFound.toString() - << "}"); + << "' in element {" << elemFound.toString() << "}"); } status = maybePadTo(&elemFound, *newIdx); diff --git a/src/mongo/db/update/path_support_test.cpp b/src/mongo/db/update/path_support_test.cpp index ecd2fa9bab5..33300f956af 100644 --- a/src/mongo/db/update/path_support_test.cpp +++ b/src/mongo/db/update/path_support_test.cpp @@ -57,10 +57,10 @@ namespace { using namespace mongo; using namespace pathsupport; -using str::stream; using mutablebson::Element; -using std::unique_ptr; using std::string; +using std::unique_ptr; +using str::stream; class EmptyDoc : public mongo::unittest::Test { public: @@ -606,9 +606,7 @@ static void assertContains(const EqualityMatches& equalities, const BSONObj& wra &SimpleStringDataComparator::kInstance); if (eltCmp.evaluate(it->second->getData() != value)) { FAIL(stream() << "Equality match at path \"" << path << "\" contains value " - << it->second->getData() - << ", not value " - << value); + << it->second->getData() << ", not value " << value); } } @@ -898,19 +896,14 @@ static void assertParent(const EqualityMatches& equalities, StringData foundParentPath = path.dottedSubstring(0, parentPathPart); if (foundParentPath != parentPath) { FAIL(stream() << "Equality match parent at path \"" << foundParentPath - << "\" does not match \"" - << parentPath - << "\""); + << "\" does not match \"" << parentPath << "\""); } BSONElementComparator eltCmp(BSONElementComparator::FieldNamesMode::kIgnore, &SimpleStringDataComparator::kInstance); if (eltCmp.evaluate(parentEl != value)) { FAIL(stream() << "Equality match parent for \"" << pathStr << "\" at path \"" << parentPath - << "\" contains value " - << parentEl - << ", not value " - << value); + << "\" contains value " << parentEl << ", not value " << value); } } @@ -930,8 +923,7 @@ static void assertNoParent(const EqualityMatches& equalities, StringData pathStr if (!parentEl.eoo()) { StringData foundParentPath = path.dottedSubstring(0, parentPathPart); FAIL(stream() << "Equality matches contained parent for \"" << pathStr << "\" at \"" - << foundParentPath - << "\""); + << foundParentPath << "\""); } } diff --git a/src/mongo/db/update/pipeline_executor_test.cpp b/src/mongo/db/update/pipeline_executor_test.cpp index 2a10c292532..1c5c4297485 100644 --- a/src/mongo/db/update/pipeline_executor_test.cpp +++ b/src/mongo/db/update/pipeline_executor_test.cpp @@ -44,8 +44,8 @@ namespace mongo { namespace { using PipelineExecutorTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST_F(PipelineExecutorTest, Noop) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); diff --git a/src/mongo/db/update/pop_node.cpp b/src/mongo/db/update/pop_node.cpp index 35ff39204af..3d4355793f1 100644 --- a/src/mongo/db/update/pop_node.cpp +++ b/src/mongo/db/update/pop_node.cpp @@ -54,8 +54,7 @@ ModifierNode::ModifyResult PopNode::updateExistingElement( uassert(ErrorCodes::TypeMismatch, str::stream() << "Path '" << elementPath->dottedField() << "' contains an element of non-array type '" - << typeName(element->getType()) - << "'", + << typeName(element->getType()) << "'", element->getType() == BSONType::Array); if (!element->hasChildren()) { diff --git a/src/mongo/db/update/pull_node_test.cpp b/src/mongo/db/update/pull_node_test.cpp index b9092a98927..39f41ba06f1 100644 --- a/src/mongo/db/update/pull_node_test.cpp +++ b/src/mongo/db/update/pull_node_test.cpp @@ -44,8 +44,8 @@ namespace mongo { namespace { using PullNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST(PullNodeTest, InitWithBadMatchExpressionFails) { auto update = fromjson("{$pull: {a: {b: {$foo: 1}}}}"); diff --git a/src/mongo/db/update/pullall_node.cpp b/src/mongo/db/update/pullall_node.cpp index e4c0936fa83..e6e9e4570cd 100644 --- a/src/mongo/db/update/pullall_node.cpp +++ b/src/mongo/db/update/pullall_node.cpp @@ -48,7 +48,7 @@ public: bool match(const mutablebson::ConstElement& element) final { return std::any_of(_elementsToMatch.begin(), _elementsToMatch.end(), - [&element, collator{_collator} ](const auto& elementToMatch) { + [&element, collator{_collator}](const auto& elementToMatch) { return element.compareWithBSONElement( elementToMatch, collator, false) == 0; }); diff --git a/src/mongo/db/update/pullall_node_test.cpp b/src/mongo/db/update/pullall_node_test.cpp index 60b09e7b77d..dd77b411dcf 100644 --- a/src/mongo/db/update/pullall_node_test.cpp +++ b/src/mongo/db/update/pullall_node_test.cpp @@ -44,8 +44,8 @@ namespace mongo { namespace { using PullAllNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST(PullAllNodeTest, InitWithIntFails) { auto update = fromjson("{$pullAll: {a: 1}}"); diff --git a/src/mongo/db/update/push_node.cpp b/src/mongo/db/update/push_node.cpp index 6702af4fec3..a4a79fb6e5a 100644 --- a/src/mongo/db/update/push_node.cpp +++ b/src/mongo/db/update/push_node.cpp @@ -292,10 +292,8 @@ ModifierNode::ModifyResult PushNode::performPush(mutablebson::Element* element, uasserted(ErrorCodes::BadValue, str::stream() << "The field '" << elementPath->dottedField() << "'" << " must be an array but is of type " - << typeName(element->getType()) - << " in document {" - << (idElem.ok() ? idElem.toString() : "no id") - << "}"); + << typeName(element->getType()) << " in document {" + << (idElem.ok() ? idElem.toString() : "no id") << "}"); } auto result = insertElementsWithPosition(element, _position, _valuesToPush); diff --git a/src/mongo/db/update/push_node_test.cpp b/src/mongo/db/update/push_node_test.cpp index d0ef73e22e5..985ee81ca2c 100644 --- a/src/mongo/db/update/push_node_test.cpp +++ b/src/mongo/db/update/push_node_test.cpp @@ -44,8 +44,8 @@ namespace mongo { namespace { using PushNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST(PushNodeTest, EachClauseWithNonArrayObjectFails) { auto update = fromjson("{$push: {x: {$each: {'0': 1}}}}"); @@ -670,12 +670,9 @@ void checkDocumentAndResult(BSONObj updateModifier, FAIL(str::stream() << "apply() failure for " << updateModifier << ". Expected " << expectedDocument << " (noop = false, indexesAffected = false) but got " - << actualDocument.toString() - << " (noop = " - << (applyResult.noop ? "true" : "false") - << ", indexesAffected = " - << (applyResult.indexesAffected ? "true" : "false") - << ")."); + << actualDocument.toString() << " (noop = " + << (applyResult.noop ? "true" : "false") << ", indexesAffected = " + << (applyResult.indexesAffected ? "true" : "false") << ")."); } } @@ -828,9 +825,7 @@ TEST_F(PushNodeTest, ApplyToPopulatedArrayWithSortAndSliceValues) { auto update = BSON("$push" << BSON("a" << BSON("$each" << BSON_ARRAY(BSON("a" << 2 << "b" << 1) << BSON("a" << 1 << "b" << 1)) - << "$slice" - << data.sliceValue - << "$sort" + << "$slice" << data.sliceValue << "$sort" << data.sortOrder))); boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); PushNode node; diff --git a/src/mongo/db/update/rename_node.cpp b/src/mongo/db/update/rename_node.cpp index bdf968664d0..ba9446c5789 100644 --- a/src/mongo/db/update/rename_node.cpp +++ b/src/mongo/db/update/rename_node.cpp @@ -133,8 +133,8 @@ Status RenameNode::init(BSONElement modExpr, // Though we could treat this as a no-op, it is illegal in the current implementation. if (fromFieldRef == toFieldRef) { return Status(ErrorCodes::BadValue, - str::stream() << "The source and target field for $rename must differ: " - << modExpr); + str::stream() + << "The source and target field for $rename must differ: " << modExpr); } if (fromFieldRef.isPrefixOf(toFieldRef) || toFieldRef.isPrefixOf(fromFieldRef)) { @@ -203,12 +203,10 @@ UpdateExecutor::ApplyResult RenameNode::apply(ApplyParams applyParams, auto idElem = mutablebson::findFirstChildNamed(document.root(), "_id"); uasserted(ErrorCodes::BadValue, str::stream() << "The source field cannot be an array element, '" - << fromFieldRef->dottedField() - << "' in doc with " + << fromFieldRef->dottedField() << "' in doc with " << (idElem.ok() ? idElem.toString() : "no id") << " has an array field called '" - << currentElement.getFieldName() - << "'"); + << currentElement.getFieldName() << "'"); } } @@ -225,12 +223,10 @@ UpdateExecutor::ApplyResult RenameNode::apply(ApplyParams applyParams, auto idElem = mutablebson::findFirstChildNamed(document.root(), "_id"); uasserted(ErrorCodes::BadValue, str::stream() << "The destination field cannot be an array element, '" - << toFieldRef.dottedField() - << "' in doc with " + << toFieldRef.dottedField() << "' in doc with " << (idElem.ok() ? idElem.toString() : "no id") << " has an array field called '" - << currentElement.getFieldName() - << "'"); + << currentElement.getFieldName() << "'"); } } diff --git a/src/mongo/db/update/rename_node_test.cpp b/src/mongo/db/update/rename_node_test.cpp index 93ddfd61714..6eec4d8f498 100644 --- a/src/mongo/db/update/rename_node_test.cpp +++ b/src/mongo/db/update/rename_node_test.cpp @@ -43,8 +43,8 @@ namespace mongo { namespace { using RenameNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; TEST(RenameNodeTest, PositionalNotAllowedInFromField) { auto update = fromjson("{$rename: {'a.$': 'b'}}"); @@ -476,8 +476,7 @@ TEST_F(RenameNodeTest, ApplyCanRemoveRequiredPartOfDBRefIfValidateForStorageIsFa ASSERT_TRUE(result.indexesAffected); auto updated = BSON("a" << BSON("$ref" << "c") - << "b" - << 0); + << "b" << 0); ASSERT_EQUALS(updated, doc); ASSERT_FALSE(doc.isInPlaceModeEnabled()); ASSERT_EQUALS(fromjson("{$set: {'b': 0}, $unset: {'a.$id': true}}"), getLogDoc()); diff --git a/src/mongo/db/update/set_node_test.cpp b/src/mongo/db/update/set_node_test.cpp index f7280e83110..8f160c4fe13 100644 --- a/src/mongo/db/update/set_node_test.cpp +++ b/src/mongo/db/update/set_node_test.cpp @@ -43,8 +43,8 @@ namespace mongo { namespace { using SetNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; DEATH_TEST(SetNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { auto update = fromjson("{$set: {}}"); diff --git a/src/mongo/db/update/storage_validation.cpp b/src/mongo/db/update/storage_validation.cpp index ce5147f42e2..009343776f0 100644 --- a/src/mongo/db/update/storage_validation.cpp +++ b/src/mongo/db/update/storage_validation.cpp @@ -104,8 +104,7 @@ void validateDollarPrefixElement(mutablebson::ConstElement elem) { // Not an okay, $ prefixed field name. uasserted(ErrorCodes::DollarPrefixedFieldName, str::stream() << "The dollar ($) prefixed field '" << elem.getFieldName() - << "' in '" - << mutablebson::getFullName(elem) + << "' in '" << mutablebson::getFullName(elem) << "' is not valid for storage."); } } diff --git a/src/mongo/db/update/unset_node_test.cpp b/src/mongo/db/update/unset_node_test.cpp index 346c5e4551c..09788ef573b 100644 --- a/src/mongo/db/update/unset_node_test.cpp +++ b/src/mongo/db/update/unset_node_test.cpp @@ -43,8 +43,8 @@ namespace mongo { namespace { using UnsetNodeTest = UpdateNodeTest; -using mongo::mutablebson::Element; using mongo::mutablebson::countChildren; +using mongo::mutablebson::Element; DEATH_TEST(UnsetNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { auto update = fromjson("{$unset: {}}"); diff --git a/src/mongo/db/update/update_array_node.h b/src/mongo/db/update/update_array_node.h index 7d942698953..c6e90c1d9c3 100644 --- a/src/mongo/db/update/update_array_node.h +++ b/src/mongo/db/update/update_array_node.h @@ -86,7 +86,7 @@ public: FieldRef* currentPath, std::map<std::string, std::vector<std::pair<std::string, BSONObj>>>* operatorOrientedUpdates) const final { - for (const auto & [ pathSuffix, child ] : _children) { + for (const auto& [pathSuffix, child] : _children) { FieldRef::FieldRefTempAppend tempAppend(*currentPath, toArrayFilterIdentifier(pathSuffix)); child->produceSerializationMap(currentPath, operatorOrientedUpdates); diff --git a/src/mongo/db/update/update_driver.cpp b/src/mongo/db/update/update_driver.cpp index 7dab889aa35..8f7024f80c1 100644 --- a/src/mongo/db/update/update_driver.cpp +++ b/src/mongo/db/update/update_driver.cpp @@ -76,26 +76,21 @@ modifiertable::ModifierType validateMod(BSONElement mod) { uassert( ErrorCodes::FailedToParse, str::stream() - << "Unknown modifier: " - << mod.fieldName() + << "Unknown modifier: " << mod.fieldName() << ". Expected a valid update modifier or pipeline-style update specified as an array", modType != modifiertable::MOD_UNKNOWN); uassert(ErrorCodes::FailedToParse, str::stream() << "Modifiers operate on fields but we found type " - << typeName(mod.type()) - << " instead. For example: {$mod: {<field>: ...}}" - << " not {" - << mod - << "}", + << typeName(mod.type()) << " instead. For example: {$mod: {<field>: ...}}" + << " not {" << mod << "}", mod.type() == BSONType::Object); uassert(ErrorCodes::FailedToParse, str::stream() << "'" << mod.fieldName() << "' is empty. You must specify a field like so: " "{" - << mod.fieldName() - << ": {<field>: ...}}", + << mod.fieldName() << ": {<field>: ...}}", !mod.embeddedObject().isEmpty()); return modType; @@ -134,8 +129,7 @@ bool parseUpdateExpression( for (const auto& arrayFilter : arrayFilters) { uassert(ErrorCodes::FailedToParse, str::stream() << "The array filter for identifier '" << arrayFilter.first - << "' was not used in the update " - << updateExpr, + << "' was not used in the update " << updateExpr, foundIdentifiers.find(arrayFilter.first.toString()) != foundIdentifiers.end()); } diff --git a/src/mongo/db/update/update_leaf_node.cpp b/src/mongo/db/update/update_leaf_node.cpp index 5d1f8931b53..b09919772a2 100644 --- a/src/mongo/db/update/update_leaf_node.cpp +++ b/src/mongo/db/update/update_leaf_node.cpp @@ -52,13 +52,9 @@ void UpdateLeafNode::checkViability(mutablebson::Element element, } else { uasserted(ErrorCodes::PathNotViable, str::stream() << "Cannot use the part (" << pathToCreate.getPart(0) << ") of (" - << pathTaken.dottedField() - << "." - << pathToCreate.dottedField() - << ") to traverse the element ({" - << element.toString() - << "})"); + << pathTaken.dottedField() << "." << pathToCreate.dottedField() + << ") to traverse the element ({" << element.toString() << "})"); } } -} // namespace +} // namespace mongo diff --git a/src/mongo/db/update/update_object_node.cpp b/src/mongo/db/update/update_object_node.cpp index 6298b8389c5..27863d15ee1 100644 --- a/src/mongo/db/update/update_object_node.cpp +++ b/src/mongo/db/update/update_object_node.cpp @@ -62,8 +62,7 @@ StatusWith<std::string> parseArrayFilterIdentifier( return Status(ErrorCodes::BadValue, str::stream() << "Cannot have array filter identifier (i.e. '$[<id>]') " "element in the first position in path '" - << fieldRef.dottedField() - << "'"); + << fieldRef.dottedField() << "'"); } auto identifier = field.substr(2, field.size() - 3); @@ -71,9 +70,7 @@ StatusWith<std::string> parseArrayFilterIdentifier( if (!identifier.empty() && arrayFilters.find(identifier) == arrayFilters.end()) { return Status(ErrorCodes::BadValue, str::stream() << "No array filter found for identifier '" << identifier - << "' in path '" - << fieldRef.dottedField() - << "'"); + << "' in path '" << fieldRef.dottedField() << "'"); } if (!identifier.empty()) { @@ -190,7 +187,7 @@ void applyChild(const UpdateNode& child, BSONObj makeBSONForOperator(const std::vector<std::pair<std::string, BSONObj>>& updatesForOp) { BSONObjBuilder bob; - for (const auto & [ path, value ] : updatesForOp) + for (const auto& [path, value] : updatesForOp) bob << path << value.firstElement(); return bob.obj(); } @@ -228,8 +225,8 @@ StatusWith<bool> UpdateObjectNode::parseAndMerge( // be a string value. if (BSONType::String != modExpr.type()) { return Status(ErrorCodes::BadValue, - str::stream() << "The 'to' field for $rename must be a string: " - << modExpr); + str::stream() + << "The 'to' field for $rename must be a string: " << modExpr); } fieldRef.parse(modExpr.valueStringData()); @@ -250,8 +247,7 @@ StatusWith<bool> UpdateObjectNode::parseAndMerge( if (positional && positionalCount > 1) { return Status(ErrorCodes::BadValue, str::stream() << "Too many positional (i.e. '$') elements found in path '" - << fieldRef.dottedField() - << "'"); + << fieldRef.dottedField() << "'"); } if (positional && positionalIndex == 0) { @@ -259,8 +255,7 @@ StatusWith<bool> UpdateObjectNode::parseAndMerge( ErrorCodes::BadValue, str::stream() << "Cannot have positional (i.e. '$') element in the first position in path '" - << fieldRef.dottedField() - << "'"); + << fieldRef.dottedField() << "'"); } // Construct and initialize the leaf node. @@ -298,8 +293,7 @@ StatusWith<bool> UpdateObjectNode::parseAndMerge( return Status(ErrorCodes::ConflictingUpdateOperators, str::stream() << "Updating the path '" << fieldRef.dottedField() << "' would create a conflict at '" - << fieldRef.dottedSubstring(0, i + 1) - << "'"); + << fieldRef.dottedSubstring(0, i + 1) << "'"); } } else { std::unique_ptr<UpdateInternalNode> ownedChild; @@ -335,10 +329,9 @@ StatusWith<bool> UpdateObjectNode::parseAndMerge( if (current->getChild(childName)) { return Status(ErrorCodes::ConflictingUpdateOperators, - str::stream() << "Updating the path '" << fieldRef.dottedField() - << "' would create a conflict at '" - << fieldRef.dottedField() - << "'"); + str::stream() + << "Updating the path '" << fieldRef.dottedField() + << "' would create a conflict at '" << fieldRef.dottedField() << "'"); } current->setChild(std::move(childName), std::move(leaf)); @@ -389,12 +382,12 @@ BSONObj UpdateObjectNode::serialize() const { BSONObjBuilder bob; - for (const auto & [ pathPrefix, child ] : _children) { + for (const auto& [pathPrefix, child] : _children) { auto path = FieldRef(pathPrefix); child->produceSerializationMap(&path, &operatorOrientedUpdates); } - for (const auto & [ op, updates ] : operatorOrientedUpdates) + for (const auto& [op, updates] : operatorOrientedUpdates) bob << op << makeBSONForOperator(updates); return bob.obj(); diff --git a/src/mongo/db/update/update_object_node.h b/src/mongo/db/update/update_object_node.h index 6f9bed7357a..d7f2e56e9de 100644 --- a/src/mongo/db/update/update_object_node.h +++ b/src/mongo/db/update/update_object_node.h @@ -111,7 +111,7 @@ public: FieldRef* currentPath, std::map<std::string, std::vector<std::pair<std::string, BSONObj>>>* operatorOrientedUpdates) const final { - for (const auto & [ pathSuffix, child ] : _children) { + for (const auto& [pathSuffix, child] : _children) { FieldRef::FieldRefTempAppend tempAppend(*currentPath, pathSuffix); child->produceSerializationMap(currentPath, operatorOrientedUpdates); } diff --git a/src/mongo/db/update/update_serialization_test.cpp b/src/mongo/db/update/update_serialization_test.cpp index 046efec9825..89ae2ac03c4 100644 --- a/src/mongo/db/update/update_serialization_test.cpp +++ b/src/mongo/db/update/update_serialization_test.cpp @@ -248,4 +248,4 @@ TEST(UpdateSerialization, CompoundStatementsSerialize) { } } // namespace -} // mongo +} // namespace mongo |