Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to ping mongodb from pymongo

M using pymongo for connecting with a mLab-hosted mongodb.

I need to keep pinging the server occassionally to keep the connection alive.

I have not been able to find documentation for that.

Kindly suggest the pymongo equivalent of ping command.

like image 967
Vishal Avatar asked Mar 02 '17 20:03

Vishal


1 Answers

You can use pymongo.database.Database.command to send custom command like:

from pymongo import MongoClient
client = MongoClient()
client.db_name.command('ping')

returns

{u'ok': 1.0}
like image 137
Arount Avatar answered Oct 03 '22 21:10

Arount