Question

J'ai un serveur Web en cours d'exécution en Python. Il obtient des données de certaines applications et doivent stocker dans MongoDB. Mon MongoDB est fragmentées. Maintenant, je veux que mon Webserver savoir combien Shards MongoDB a. Au moment où il lit ce à partir d'un fichier CFG. Il y a une déclaration dans MongoDB nommé printshardingstatus où l'on peut voir tous les tessons. Donc, j'ai essayé d'appeler cette déclaration de mon Pythonserver. Mais il semble que ce n'est pas possible.I ne trouvent pas une telle fonction dans l'API Pymongo.

Alors ma question est, est-il une chance d'exécuter une instruction MongoDB en Python, de sorte qu'il est directement passé et exécuté dans MongoDB?

Était-ce utile?

La solution

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: " +
   ...

Autres conseils

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

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top