[SERVER-41854] Add expression that evaluates to shardName Created: 21/Jun/19  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework, Querying
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Anton Korshunov Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: expression, pull-request
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Sprint: Query 2019-07-29, Query 2019-10-07
Participants:

 Description   

For troubleshooting and testing purposes it could be very helpful to be able to quickly check data distribution in a collection. This could be done by adding an ability to project out the shard name for a document. For example,

 

db.employee.insert({_id: 1, name: "Joe Smith"})
db.employee.insert({_id: 2, name: "Mary Scott"})
db.employee.insert({_id: 3, name: "Ann Power"})
db.employee.aggregate([{$addFields: {shardName: {$shardName: 1}}}])
{ "_id" : 1, "name" : "Joe Smith", "shardName" : "shard0" }
{ "_id" : 2, "name" : "Mary Scott", "shardName" : "shard0" }
{ "_id" : 3, "name" : "Ann Power", "shardName" : "shard1" }

 



 Comments   
Comment by Katya Kamenieva [ 29/May/20 ]

krk, thank you for the pull request and review followups. Currently, this feature is not on the list of our immediate priorities. Once it gets prioritized, we'll work with you to make it happen.

Comment by David Storch [ 09/Oct/19 ]

Thanks krk! I responded on the pull request with a few pieces of feedback.

Comment by Kerem Kat [ 06/Jul/19 ]

I have created PR 1317 that adds this functionality in the form of a $meta projection.

See the PR comment for details.

Example:

db.items.find({}, {shard: {$meta: "shardName"}}) 
{ "_id" : 1, "a" : 1, "foo" : 1, "shard" : "toe" }
{ "_id" : 5, "a" : 5, "foo" : 5, "shard" : "toe" }
{ "_id" : 2, "a" : 2, "foo" : 2, "shard" : "tic" }
{ "_id" : 3, "a" : 3, "foo" : 3, "shard" : "tic" }
{ "_id" : 4, "a" : 4, "foo" : 4, "shard" : "tic" }

Generated at Thu Feb 08 04:58:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.