Which mongo shell do you use?
As far as I remember command getShardDistribution()
was not working in older mongosh
version. Update Mongo shell to latest version, I assume then it will work.
Another option is sh.getShardedDataDistribution()
command:
sh.getShardedDataDistribution().toArray().filter(x=> x.ns == 'test.weather').shift().shards
[
{
shardName: 'shard_02',
numOrphanedDocs: 0,
numOwnedDocuments: 32707096,
ownedSizeBytes: Long('5854570184'),
orphanedSizeBytes: 0
},
{
shardName: 'shard_01',
numOrphanedDocs: 0,
numOwnedDocuments: 32680397,
ownedSizeBytes: Long('5849791063'),
orphanedSizeBytes: 0
},
{
shardName: 'shard_04',
numOrphanedDocs: 0,
numOwnedDocuments: 35894266,
ownedSizeBytes: Long('5635399762'),
orphanedSizeBytes: 0
},
{
shardName: 'shard_03',
numOrphanedDocs: 0,
numOwnedDocuments: 30664963,
ownedSizeBytes: Long('5458363414'),
orphanedSizeBytes: 0
}
]
Or you query it manually:
db.getSiblingDB("config").chunks.aggregate([
{ $lookup: { from: "collections", localField: "uuid", foreignField: "uuid", as: "collection" } },
{ $set: { collection: "$$REMOVE", balancing: { $not: { $first: "$collection.noBalance" } }, ns: { $first: "$collection._id" } } },
{ $match: { ns: 'data.sessions.20231230' } },
{ $group: { _id: { shard: "$shard", ns: "$ns", balancing: "$balancing", uuid: "$uuid" }, chunks: { $count: {} } } },
// { $group: { _id: { ns: "$_id.ns", uuid: "$_id.uuid", balancing: "$_id.balancing" }, sum: { $sum: "$chunks" }, shards: { $push: { shard: "$_id.shard", chunks: "$chunks" } } } },
])
Just a note, in earlier MongoDB versions, the balancer distributed data to have even number of chunks across the shards. In current released the goal is to get even data sizes.
sh.status()
(this needs to be run from themongos
router of your sharded cluster).