File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
src/main/java/com/mongodb/spark/sql/connector/read/partitioner Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,6 @@ private List<BsonDocument> createUpperBounds(
8989 : Projections .fields (Projections .include (partitionField ), Projections .excludeId ());
9090
9191 List <Bson > aggregationPipeline = new ArrayList <>(readConfig .getAggregationPipeline ());
92- aggregationPipeline .add (Aggregates .project (projection ));
9392 aggregationPipeline .add (Aggregates .sort (Sorts .ascending (partitionField )));
9493
9594 BsonDocument boundary = readConfig .withCollection (coll -> {
@@ -108,6 +107,9 @@ private List<BsonDocument> createUpperBounds(
108107 boundaryPipeline .addAll (aggregationPipeline );
109108 boundaryPipeline .add (Aggregates .skip (numDocumentsPerPartition ));
110109 boundaryPipeline .add (Aggregates .limit (1 ));
110+ // $project at the end of the pipeline as per SERVER-49306.
111+ // Ensures indexes can be utilized for the $skip stage
112+ boundaryPipeline .add (Aggregates .project (projection ));
111113 return coll .aggregate (boundaryPipeline )
112114 .allowDiskUse (readConfig .getAggregationAllowDiskUse ())
113115 .comment (readConfig .getComment ())
You can’t perform that action at this time.
0 commit comments