diff options
-rw-r--r-- | src/mongo/db/query/canonical_query.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/query/canonical_query_test.cpp | 7 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index f95b9aac680..ff9e100ca99 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -180,10 +180,10 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( // static StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( OperationContext* opCtx, const CanonicalQuery& baseQuery, MatchExpression* root) { - // TODO: we should be passing the filter corresponding to 'root' to the QR rather than the base - // query's filter, baseQuery.getQueryRequest().getFilter(). auto qr = stdx::make_unique<QueryRequest>(baseQuery.nss()); - qr->setFilter(baseQuery.getQueryRequest().getFilter()); + BSONObjBuilder builder; + root->serialize(&builder); + qr->setFilter(builder.obj()); qr->setProj(baseQuery.getQueryRequest().getProj()); qr->setSort(baseQuery.getQueryRequest().getSort()); qr->setCollation(baseQuery.getQueryRequest().getCollation()); diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp index a745b06a8ef..0aa386b9800 100644 --- a/src/mongo/db/query/canonical_query_test.cpp +++ b/src/mongo/db/query/canonical_query_test.cpp @@ -307,10 +307,9 @@ TEST(CanonicalQueryTest, CanonicalizeFromBaseQuery) { MatchExpression* firstClauseExpr = baseCq->root()->getChild(0); auto childCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), *baseCq, firstClauseExpr)); - // Descriptive test. The childCq's filter should be the relevant $or clause, rather than the - // entire query predicate. - ASSERT_BSONOBJ_EQ(childCq->getQueryRequest().getFilter(), - baseCq->getQueryRequest().getFilter()); + BSONObjBuilder expectedFilter; + firstClauseExpr->serialize(&expectedFilter); + ASSERT_BSONOBJ_EQ(childCq->getQueryRequest().getFilter(), expectedFilter.obj()); ASSERT_BSONOBJ_EQ(childCq->getQueryRequest().getProj(), baseCq->getQueryRequest().getProj()); ASSERT_BSONOBJ_EQ(childCq->getQueryRequest().getSort(), baseCq->getQueryRequest().getSort()); |