Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Created May 19, 2015 01:41
Show Gist options
  • Save seansullivan/0ff18287f24820235a7f to your computer and use it in GitHub Desktop.
Save seansullivan/0ff18287f24820235a7f to your computer and use it in GitHub Desktop.
getPrimaryIpFromMongoConnection
def getPrimaryIpFromMongoConnection(mongoConnection):
# mongoConnection = MongoClient(aMongoServerIp, replicaSet=replicaSetName)
replicaSetStatus = mongoConnection.admin.command('replSetGetStatus')
for member in replicaSetStatus[u'members']:
if member[u'stateStr'] == u'PRIMARY':
return member[u'name']
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment