From 0a870f14f902b7c002ed0d12fbf44be97f08a8a4 Mon Sep 17 00:00:00 2001 From: Mihai Andrei Date: Tue, 19 Nov 2019 14:39:37 +0000 Subject: SERVER-44348 Add deprecation warning for , in mapReduce --- src/mongo/db/commands/mr.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 31e848d80fd..5edc6a426aa 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -96,8 +96,11 @@ namespace mr { namespace { Rarely mapParamsDeprecationSampler; // Used to occasionally log deprecation messages. -// Used to log occassional deprecation warnings when CodeWScope is used in MapReduce. +// Used to log occasional deprecation warnings when CodeWScope is used in MapReduce. Rarely mapReduceCodeWScopeSampler; +// Used to log occasional deprecation warnings when $near or $where are used in MapReduce. +Rarely mapReduceNearSampler; +Rarely mapReduceWhereSampler; /** @@ -225,6 +228,22 @@ void dropTempCollections(OperationContext* cleanupOpCtx, ShardConnection::forgetNS(incLong.ns()); } } +/** + * Recursive method which verifies that the query option specified to mapReduce does not use the + * specified match type. + */ +bool queryContainsMatchType(MatchExpression* root, MatchExpression::MatchType match) { + if (root->matchType() == match) { + return false; + } else if (root->numChildren() > 0) { + for (auto&& child : *(root->getChildVector())) { + if (!queryContainsMatchType(child, match)) { + return false; + } + } + } + return true; +} } // namespace @@ -1545,6 +1564,15 @@ public: MatchExpressionParser::kAllowAllSpecialFeatures), str::stream() << "Can't canonicalize query " << config.filter); + if (!queryContainsMatchType(cq->root(), MatchExpression::MatchType::GEO_NEAR) && + mapReduceNearSampler.tick()) { + warning() << "The use of $near in the query option to MapReduce is deprecated"; + } + if (!queryContainsMatchType(cq->root(), MatchExpression::MatchType::WHERE) && + mapReduceWhereSampler.tick()) { + warning() << "The use of $where in the query option to MapReduce is deprecated"; + } + auto exec = uassertStatusOK(getExecutor(opCtx, scopedAutoColl->getCollection(), std::move(cq), -- cgit v1.2.1