-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 4.0.0, 4.1.4
-
Component/s: Aggregation Framework
-
None
-
Fully Compatible
-
ALL
-
v4.0
-
45
The $changeStream stage is implemented by parsing as a single stage, but expanding into several internal-only stages for execution. One of those stages (DocumentSourceOplogMatch) is responsible for enforcing that it must be the first stage in the pipeline.
Unfortunately, there are some cases where we never send a $changeStream to a shard, and so we never create a DocumentSourceOplogMatch, and so it is never enforced that it must be the first stage in the pipeline. For example, the following pipeline should be illegal, but the $changeStream stage stays on mongos, because the $sort stage forces a split in the pipeline and keeps the merging half on mongos:
db.sharded_collection.aggregate([{$sort: {x: 1}}, {$changeStream: {}}])