commit 09037f2b69820c16dd68b03dd887b54679d69faa Author: Charlie Swanson Date: Tue Feb 23 19:06:36 2021 -0500 WIP from meeting diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index 7ef37bc2e0..1f49ba64ec 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -1148,6 +1148,26 @@ StatusWithMatchExpression parseGeo(StringData name, } } +template +StatusWithMatchExpression parseTreeTopLevelUnary( + StringData name, + BSONElement elem, + const boost::intrusive_ptr& expCtx, + const ExtensionsCallback* extensionsCallback, + MatchExpressionParser::AllowedFeatureSet allowedFeatures, + DocumentParseLevel currentLevel) { + if (elem.type() != BSONType::Object) { + return {Status(ErrorCodes::BadValue, str::stream() << T::kName << " must be an object")}; + } + auto sub = parse(elem.Obj(), expCtx, extensionsCallback, allowedFeatures, currentLevel); + if (!sub.isOK()) + return sub.getStatus(); + + return std::make_unique(sub.getValue().release(), + doc_validation_error::createAnnotation( + expCtx, elem.fieldNameStringData().toString(), BSONObj())); +} + template StatusWithMatchExpression parseTreeTopLevel( StringData name, @@ -2024,6 +2044,7 @@ MONGO_INITIALIZER(PathlessOperatorMap)(InitializerContext* context) { {"id", &parseDBRef}, {"jsonSchema", &parseJSONSchema}, {"nor", &parseTreeTopLevel}, + {"not", &parseTreeTopLevelUnary}, {"or", &parseTreeTopLevel}, {"ref", &parseDBRef}, {"sampleRate", &parseSampleRate}, @@ -2123,4 +2144,4 @@ boost::optional MatchExpressionParser::parsePathAcceptingK } return defaultKeyword; } -} // namespace mongo +} // namespace mongo \ No newline at end of file diff --git a/src/mongo/db/matcher/expression_tree.h b/src/mongo/db/matcher/expression_tree.h index 25d71dde78..c8ae59c1eb 100644 --- a/src/mongo/db/matcher/expression_tree.h +++ b/src/mongo/db/matcher/expression_tree.h @@ -227,6 +227,7 @@ public: class NotMatchExpression final : public MatchExpression { public: + static constexpr StringData kName = "$not"_sd; explicit NotMatchExpression(MatchExpression* e, clonable_ptr annotation = nullptr) : MatchExpression(NOT, std::move(annotation)), _exp(e) {}