Cmag
Cmag

Reputation: 15770

python script to connect to mongodb master

I need to write a script to deploy Databases/Collections/Indexes.

Boto gives me a list of IPs to connect to.

What is the preferred way to figure out which mongo instance from a list is primary using pymongo? Should I loop through them or is there a more elegant approach?

Upvotes: 1

Views: 345

Answers (1)

Cmag
Cmag

Reputation: 15770

primary = ''
for inst in instances:
    client = MongoClient(inst, 8000)
    if client.is_primary:
        primary = inst
return primary

Upvotes: 1

Related Questions