File size: 1,173 Bytes
034ba67
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "sys-0035", "name": "MongoDB Shard Filtering"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer."}}
{"type": "message", "message": {"role": "user", "content": "How does MongoDB filter documents during sharded queries?"}}
{"type": "message", "message": {"role": "assistant", "content": "MongoDB uses two mechanisms to handle orphaned documents:\n\n1. ShardFilterStage (classic engine):\n   - Drops documents not belonging to this shard\n   - Holds ScopedCollectionFilter preventing deletion during active queries\n   - Uses ShardFiltererImpl for shard key evaluation\n\n2. OrphanChunkSkipper (index/distinct scans):\n   - Detects orphan keys during seeks\n   - Seeks to next owned chunk boundary\n   - Returns Info enum: NotOrphan/CanSkipOrphans/NoMoreOwned\n\nAggregation pipeline sharding:\n- InternalShredDocumentsStage: distributes documents across shards\n- InternalSplitPipelineStage: splits pipeline for scatter-gather\n- ExchangeStage: exchange-based parallelism\n\nWrite path references: oplog writes, read concern levels, transaction coordinator integration."}}