Search code examples
mongodbserverpymongoshutdown

Shut down mongod process using Pymongo


How do I terminate a mongod process with python using pymongo? Basically, the equivalent of

use admin db.shutdownServer()

which is used in the mongo shell.

Thanks


Solution

  • You can use the eval method. Connect to admin database and execute

    db.eval("db.shutdownServer()")
    

    http://api.mongodb.org/python/current/api/pymongo/database.html

    Please be noted though: Can be a security loophole. You should not give admin access to your mongodb instance from the application. That should be handled as part of your deployment steps. Hope it helps.