38
38
#include " mongo/db/exec/filter.h"
39
39
#include " mongo/db/exec/scoped_timer.h"
40
40
#include " mongo/db/exec/working_set_common.h"
41
+ #include " mongo/db/s/sharding_state.h"
41
42
#include " mongo/s/shard_key_pattern.h"
42
43
#include " mongo/util/log.h"
43
44
@@ -53,8 +54,10 @@ const char* ShardFilterStage::kStageType = "SHARDING_FILTER";
53
54
ShardFilterStage::ShardFilterStage (OperationContext* opCtx,
54
55
ScopedCollectionMetadata metadata,
55
56
WorkingSet* ws,
56
- std::unique_ptr<PlanStage> child)
57
- : PlanStage(kStageType , opCtx), _ws(ws), _shardFilterer(std::move(metadata)) {
57
+ std::unique_ptr<PlanStage> child,
58
+ bool wantShardName)
59
+ : PlanStage(kStageType , opCtx), _ws(ws), _shardFilterer(std::move(metadata)),
60
+ _wantShardName (wantShardName) {
58
61
_children.emplace_back (std::move (child));
59
62
}
60
63
@@ -104,6 +107,13 @@ PlanStage::StageState ShardFilterStage::doWork(WorkingSetID* out) {
104
107
++_specificStats.chunkSkips ;
105
108
return PlanStage::NEED_TIME;
106
109
}
110
+
111
+ if (wantShardName ()) {
112
+ auto sharding = ShardingState::get (this ->getOpCtx ());
113
+
114
+ // Populate the working set member with the shard name and return it.
115
+ member->metadata ().setShardName (sharding->shardId ());
116
+ }
107
117
}
108
118
109
119
// If we're here either we have shard state and our doc passed, or we have no shard
0 commit comments