[CSHARP-4584] Command printShardingStatus failed: no such cmd: printShardingStatus Created: 27/Mar/23  Updated: 27/Oct/23  Resolved: 11/Apr/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Unknown
Reporter: meng Alicia Assignee: Dmitry Lukyanov (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

 I want to get the  collection shard key infomation and used the following code, whitch return error with  "Command printShardingStatus failed: no such cmd: printShardingStatus"

```

using MongoDB.Driver; var client = new MongoClient("mongodb://reeeer:3*eefhu@124.9.75.107:8888,124.9.76.69:8888"); var database = client.GetDatabase("admin"); var command = new BsonDocument {

{"printShardingStatus", 1}

}; var result = database.RunCommand(command); // 输出结果 Console.WriteLine(result);

```

And the version of mongodb.driver is 2.19.0, the version of mongodb is 4.0.2;

The account has administrator privileges;

Dose the driver didn't support the printShardingStatus cmd or is there an error in  my code?

 



 Comments   
Comment by PM Bot [ 11/Apr/23 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by PM Bot [ 04/Apr/23 ]

Hey 961394844@qq.com, We need additional details to investigate the problem. If this is still an issue for you, please provide the requested information.

Comment by Dmitry Lukyanov (Inactive) [ 27/Mar/23 ]

Hey 961394844@qq.com,
"printShardingStatus" is a shell helper that is not presented as the server command or in the driver.
You can get a similar result with the server command

{ listShards : 1 }

You can also inspect other server side sharding commands here.

If you need exact response as from the "printShardingStatus" helper. You can analyze the shell javascript and implement similar logic in the driver. To get the shell javascript you can type the following in the shell:

MongoDB Enterprise replset:PRIMARY> db.printShardingStatus
function(verbose) {
    printShardingStatus(this.getSiblingDB("config"), verbose);
}

where the code inside printShardingStatus itself can be get in the same way:

MongoDB Enterprise replset:PRIMARY> printShardingStatus
function printShardingStatus(configDB, verbose) {
    // configDB is a DB object that contains the sharding metadata of interest.
    // Defaults to the db named "config" on the current connection.
    if (configDB === undefined)
        configDB = db.getSiblingDB('config');
    var version = configDB.getCollection("version").findOne();
...

Proceeding with this approach and If you dive deeper into the printShardingStatus() function, you'll see it's just issuing find() on the config database along with some group() queries.

Generated at Wed Feb 07 21:48:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.