Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ public static Aggregation fromPipeline(List<Document> pipeline, DatabaseResolver
}

private List<Document> runStages() {
// Only apply index optimization if there are no variables to inject
// Variables need to be added to documents before $match can evaluate them
if (!hasVariables()) {
return stages.stream()
.filter(stage -> stage instanceof MatchStage)
.findFirst()
.map(match -> runStages(collection.handleQueryAsStream(((MatchStage) match).getQuery())))
.orElseGet(() -> runStages(collection.queryAllAsStream()));
}
return runStages(collection.queryAllAsStream());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public String name() {
public Stream<Document> apply(Stream<Document> stream) {
return stream.filter(document -> queryMatcher.matches(document, query));
}

public Document getQuery() {
return query;
}
}