0

I have a Webserver running in Python. He is getting some Data from some Apps and need to store these in MongoDB. My MongoDB is sharded. Now i want that my Webserver know how much Shards MongoDB has. At the moment he reads this from a cfg file. There is an Statement in MongoDb named printshardingstatus where u can see all shards. So i tried to call this statement from my Pythonserver. But it seems that it is not possible.I dont find such a function in the Pymongo API.

So my question is, is there an chance to run an MongoDB Statement in Python, so that it is directly passed and executed in MongoDB ?

3 Answers 3

1

There is no server command for printShardingStatus -- it is just a mongo (javascript) shell helper function. The helper is a few queries against the config database and then some grouping and formatting to make things look nicer.

If you ever want to see how things work in the javascript shell you can just remove the parens ("()") from the function and it will print the javascript code.

Here is the code from the javascript shell.

> printShardingStatus
function (configDB, verbose) {
   if (configDB === undefined) {
       configDB = db.getSisterDB("config");
   }
   var version = configDB.getCollection("version").findOne();
   if (version == null) {
       print("not a shard db!");
       return;
   }
   var raw = "";
   var output = function (s) {raw += s + "\n";};
   output("--- Sharding Status --- ");
   output("  sharding version: " +
   ...
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried pymongo or mongoengine? Then perhaps send a message to the authors...

2 Comments

found the answer ... there is an command function where u can put the statement in
great - for anyone else reading this in future, please share an example :-)
0

You can simply get config databasr and execute find() on shards collection just like normal collection.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.