0
[direct: mongos] test> db.weather.getShardDistribution()
MongoshInvalidInputError: [SHAPI-10001] Collection weather is not sharded

we are getting this error and how to check the sharded collection data distribution for time series collection. Please share the details with query output if any one have already working on sharded time series collection.

Below is the command i used to create time series sharded collection sh.shardCollection( “test.weather”, { “uid”: 1 }, { timeseries: { timeField: “et”, metaField: “uid” ,granularity: “hours” } })

1
  • What is the output from the sh.status() (this needs to be run from the mongos router of your sharded cluster).
    – prasad_
    Jan 18 at 10:03

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.