diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-10-02 17:24:03 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-10-05 16:47:26 -0400 |
commit | cb9f7cdcb7eb6ad9077ac8af3a4c0d7275c7e34f (patch) | |
tree | 24fea4c596a4652a457bc496d34a5590b7882190 /src/mongo/db/update | |
parent | e02285559b5f15be6afbf876f169874bd9008b0b (diff) | |
download | mongo-cb9f7cdcb7eb6ad9077ac8af3a4c0d7275c7e34f.tar.gz |
SERVER-30731 Add expr support in MatchExpression outside of aggregation
Diffstat (limited to 'src/mongo/db/update')
-rw-r--r-- | src/mongo/db/update/pull_node.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/update/pull_node_test.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/update/update_driver.cpp | 2 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/mongo/db/update/pull_node.cpp b/src/mongo/db/update/pull_node.cpp index b712e2ece4e..2e29b3a9527 100644 --- a/src/mongo/db/update/pull_node.cpp +++ b/src/mongo/db/update/pull_node.cpp @@ -42,7 +42,10 @@ namespace mongo { class PullNode::ObjectMatcher final : public PullNode::ElementMatcher { public: ObjectMatcher(BSONObj matchCondition, const boost::intrusive_ptr<ExpressionContext>& expCtx) - : _matchExpr(matchCondition, expCtx) {} + : _matchExpr(matchCondition, + expCtx, + stdx::make_unique<ExtensionsCallbackNoop>(), + MatchExpressionParser::kBanAllSpecialFeatures) {} std::unique_ptr<ElementMatcher> clone() const final { return stdx::make_unique<ObjectMatcher>(*this); @@ -75,7 +78,10 @@ class PullNode::WrappedObjectMatcher final : public PullNode::ElementMatcher { public: WrappedObjectMatcher(BSONElement matchCondition, const boost::intrusive_ptr<ExpressionContext>& expCtx) - : _matchExpr(matchCondition.wrap(""), expCtx) {} + : _matchExpr(matchCondition.wrap(""), + expCtx, + stdx::make_unique<ExtensionsCallbackNoop>(), + MatchExpressionParser::kBanAllSpecialFeatures) {} std::unique_ptr<ElementMatcher> clone() const final { return stdx::make_unique<WrappedObjectMatcher>(*this); diff --git a/src/mongo/db/update/pull_node_test.cpp b/src/mongo/db/update/pull_node_test.cpp index 744abd739f4..7cfb15542cb 100644 --- a/src/mongo/db/update/pull_node_test.cpp +++ b/src/mongo/db/update/pull_node_test.cpp @@ -108,7 +108,7 @@ TEST(PullNodeTest, InitWithExprElemFails) { PullNode node; auto status = node.init(update["$pull"]["a"], expCtx); ASSERT_NOT_OK(status); - ASSERT_EQUALS(ErrorCodes::BadValue, status); + ASSERT_EQUALS(ErrorCodes::QueryFeatureNotAllowed, status); } TEST(PullNodeTest, InitWithExprObjectFails) { @@ -117,7 +117,16 @@ TEST(PullNodeTest, InitWithExprObjectFails) { PullNode node; auto status = node.init(update["$pull"]["a"], expCtx); ASSERT_NOT_OK(status); - ASSERT_EQUALS(ErrorCodes::BadValue, status); + ASSERT_EQUALS(ErrorCodes::QueryFeatureNotAllowed, status); +} + +TEST(PullNodeTest, InitWithJSONSchemaFails) { + auto update = fromjson("{$pull: {a: {$jsonSchema: {}}}}"); + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + PullNode node; + auto status = node.init(update["$pull"]["a"], expCtx); + ASSERT_NOT_OK(status); + ASSERT_EQUALS(ErrorCodes::QueryFeatureNotAllowed, status); } TEST_F(PullNodeTest, TargetNotFound) { diff --git a/src/mongo/db/update/update_driver.cpp b/src/mongo/db/update/update_driver.cpp index 7eb4f4ffd7c..5380de021ae 100644 --- a/src/mongo/db/update/update_driver.cpp +++ b/src/mongo/db/update/update_driver.cpp @@ -288,6 +288,8 @@ Status UpdateDriver::populateDocumentWithQueryFields(OperationContext* opCtx, auto qr = stdx::make_unique<QueryRequest>(NamespaceString("")); qr->setFilter(query); const boost::intrusive_ptr<ExpressionContext> expCtx; + // $expr is not allowed in the query for an upsert, since it is not clear what the equality + // extraction behavior for $expr should be. auto statusWithCQ = CanonicalQuery::canonicalize(opCtx, std::move(qr), |