summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_lookup.cpp
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-08-10 20:20:19 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-08-10 20:20:19 -0400
commitfad11e0917e79e5cfa2bb744e9ec5d1bcb97a608 (patch)
tree32eba6f1cd9558d7f0aa2fe07a4135b9f6cbd445 /src/mongo/db/pipeline/document_source_lookup.cpp
parenta0b7e4fc8cf224505267b2fe589975ba36f49078 (diff)
downloadmongo-fad11e0917e79e5cfa2bb744e9ec5d1bcb97a608.tar.gz
SERVER-24769 Add support for $lookup and $graphLookup on a view.
Diffstat (limited to 'src/mongo/db/pipeline/document_source_lookup.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp
index dc413d8fff8..73d274eef06 100644
--- a/src/mongo/db/pipeline/document_source_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup.cpp
@@ -88,7 +88,7 @@ BSONObj buildEqualityOrQuery(const std::string& fieldName, const vector<Value>&
boost::optional<Document> DocumentSourceLookUp::getNext() {
pExpCtx->checkForInterrupt();
- uassert(4567, "from collection cannot be sharded", !_mongod->isSharded(_fromNs));
+ uassert(4567, "from collection cannot be sharded", !_mongod->isSharded(_fromExpCtx->ns));
if (!_additionalFilter && _matchSrc) {
// We have internalized a $match, but have not yet computed the descended $match that should
@@ -112,7 +112,9 @@ boost::optional<Document> DocumentSourceLookUp::getNext() {
auto matchStage =
makeMatchStageFromInput(*input, _localField, _foreignFieldFieldName, BSONObj());
- auto pipeline = uassertStatusOK(_mongod->makePipeline({matchStage}, _fromExpCtx));
+ // We've already allocated space for the trailing $match stage in '_fromPipeline'.
+ _fromPipeline.back() = matchStage;
+ auto pipeline = uassertStatusOK(_mongod->makePipeline(_fromPipeline, _fromExpCtx));
std::vector<Value> results;
int objsize = 0;
@@ -357,7 +359,9 @@ boost::optional<Document> DocumentSourceLookUp::unwindResult() {
BSONObj filter = _additionalFilter.value_or(BSONObj());
auto matchStage =
makeMatchStageFromInput(*_input, _localField, _foreignFieldFieldName, filter);
- _pipeline = uassertStatusOK(_mongod->makePipeline({matchStage}, _fromExpCtx));
+ // We've already allocated space for the trailing $match stage in '_fromPipeline'.
+ _fromPipeline.back() = matchStage;
+ _pipeline = uassertStatusOK(_mongod->makePipeline(_fromPipeline, _fromExpCtx));
_cursorIndex = 0;
_nextValue = _pipeline->output()->getNext();
@@ -440,7 +444,16 @@ DocumentSource::GetDepsReturn DocumentSourceLookUp::getDependencies(DepsTracker*
}
void DocumentSourceLookUp::doInjectExpressionContext() {
- _fromExpCtx = pExpCtx->copyWith(_fromNs);
+ auto it = pExpCtx->resolvedNamespaces.find(_fromNs.coll());
+ invariant(it != pExpCtx->resolvedNamespaces.end());
+ const auto& resolvedNamespace = it->second;
+ _fromExpCtx = pExpCtx->copyWith(resolvedNamespace.ns);
+ _fromPipeline = resolvedNamespace.pipeline;
+
+ // We append an additional BSONObj to '_fromPipeline' as a placeholder for the $match stage
+ // we'll eventually construct from the input document.
+ _fromPipeline.reserve(_fromPipeline.size() + 1);
+ _fromPipeline.push_back(BSONObj());
}
void DocumentSourceLookUp::doDetachFromOperationContext() {