diff options
author | James Wahlin <james.wahlin@10gen.com> | 2016-11-15 14:29:54 -0500 |
---|---|---|
committer | James Wahlin <james.wahlin@10gen.com> | 2016-11-16 11:28:56 -0500 |
commit | ed347a4f92a3388ab0f690502a81132577361623 (patch) | |
tree | 5b0e90662137d9a8fcdf7935aaebc79761558eda /src/mongo/db | |
parent | 4344dbc672937b4d20d229a0763bfc22faf664f6 (diff) | |
download | mongo-ed347a4f92a3388ab0f690502a81132577361623.tar.gz |
SERVER-27030 Improve error for legacy find/getMore on view
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/query/find.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 079ae46c61c..0f3b27907d9 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -267,7 +267,17 @@ Message getMore(OperationContext* txn, // the data within a collection. cursorManager = CursorManager::getGlobalCursorManager(); } else { - ctx = stdx::make_unique<AutoGetCollectionForRead>(txn, nss); + ctx = stdx::make_unique<AutoGetCollectionOrViewForRead>(txn, nss); + auto viewCtx = static_cast<AutoGetCollectionOrViewForRead*>(ctx.get()); + if (viewCtx->getView()) { + uasserted( + ErrorCodes::CommandNotSupportedOnView, + str::stream() << "Namespace " << nss.ns() + << " is a view. OP_GET_MORE operations are not supported on views. " + << "Only clients which support the getMore command can be used to " + "query views."); + } + Collection* collection = ctx->getCollection(); uassert(17356, "collection dropped between getMore calls", collection); cursorManager = collection->getCursorManager(); @@ -514,9 +524,18 @@ std::string runQuery(OperationContext* txn, LOG(2) << "Running query: " << redact(cq->toStringShort()); // Parse, canonicalize, plan, transcribe, and get a plan executor. - AutoGetCollectionForRead ctx(txn, nss); + AutoGetCollectionOrViewForRead ctx(txn, nss); Collection* collection = ctx.getCollection(); + if (ctx.getView()) { + uasserted(ErrorCodes::CommandNotSupportedOnView, + str::stream() + << "Namespace " + << nss.ns() + << " is a view. Legacy find operations are not supported on views. " + << "Only clients which support the find command can be used to query views."); + } + // We have a parsed query. Time to get the execution plan for it. std::unique_ptr<PlanExecutor> exec = uassertStatusOK( getExecutorFind(txn, collection, nss, std::move(cq), PlanExecutor::YIELD_AUTO)); |