Hello, How can I run the equivalent using pymongo? cfg = rs.conf () db.printSlaveReplicationInfo ()


1>How can I run the equivalent using pymongo?


cfg = rs.conf()



2>Using PyMongo, how can I get the details of other replica sets CLI output in the created clusters . (Note:I have already successfully created cluster.Just I am writing a python script in primary to check the outputs of rs.conf() and db.printSlaveReplicationInfo() in all the replica sets inside cluster and parse the output.)

Any help on this regard is greatly appreciable.

The replica set configuration is stored in the "local" database in a collection called "system.replset" so the equivalent of rs.conf() would be db.system.replset.findOne() when db is local or its equivalent find_one() in Python.

db.printSlaveReplicationInfo() is a big more involved, but you can get all of that information in the local database as well.

It may be easier to get it via admin database command replSetGetStatus which returns a document containing oplog information for each member of the replica set, along with other details. Python MongoDB driver pymongo provides a method to run commands, so you can run it against the admin DB and parse out the output for information about where each member of the replica set is relative to the primary.