diff options
Diffstat (limited to 'src/mongo/db/pipeline/document_source_lookup.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_lookup.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp index c4e6b72947a..a3e7f29ec77 100644 --- a/src/mongo/db/pipeline/document_source_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_lookup.cpp @@ -326,6 +326,32 @@ BSONObj DocumentSourceLookUp::queryForInput(const Document& input, return query.obj(); } +BSONObjSet DocumentSourceLookUp::getOutputSorts() { + BSONObjSet out; + + BSONObjSet inputSort = pSource->getOutputSorts(); + std::string asPath = _as.getPath(false); + + for (auto&& sortObj : inputSort) { + // Truncate each sortObj at the '_as' path. + BSONObjBuilder outputSort; + + for (BSONElement fieldSort : sortObj) { + if (fieldSort.fieldNameStringData() == asPath) { + break; + } + outputSort.append(fieldSort); + } + + BSONObj outSortObj = outputSort.obj(); + if (!outSortObj.isEmpty()) { + out.insert(outSortObj); + } + } + + return out; +} + boost::optional<Document> DocumentSourceLookUp::unwindResult() { const boost::optional<FieldPath> indexPath(_unwindSrc->indexPath()); |