Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoEngine & serverStatus

I am switching my python script from using pymongo to using mongoengine. Previously, I had this call:

client_count = db.command("serverStatus")["connections"]['current'] - 1

but I want to get the number of current connections using mongoengine's wrapper instead. I looked at server-status and the mongoengine docs and was unable to find an equivalent call for pulling server variables.

I want to swap over to mongoengine because we're using its ODM features and we would like to cut out redundancy.

Any pointers for this? What is the correct syntax, if at all? Thanks.

In the meantime, we are just going to use pymongo for getting the correct data, while using mongoengine for everything else.

like image 510
Xeus Avatar asked Aug 20 '26 15:08

Xeus


1 Answers

There is no Mongoengine equivalent, so you have to call this manually. As we wrap pymongo you can do the call via getting the database from the connection register. The easiest way to do this is to use the document class eg:

db = Document._get_db()
client_count = db.command("serverStatus")["connections"]['current'] - 1
like image 68
Ross Avatar answered Aug 22 '26 07:08

Ross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!