Christian Jensen
Christian Jensen

Reputation: 55

Detect if mongoDB server is master via official C# driver?

I am trying to detect if a server in a replica set is a master or slave node using the official MongoDB C# driver. I can't seem to find anything corresponding to the isMaster() method (used in the shell) in the driver. Isn't there any way to detect if a server is master from C#?

Upvotes: 1

Views: 818

Answers (1)

dampier
dampier

Reputation: 5126

If you have a MongoServer s, I believe you can just say

s.Instance.IsPrimary

or

s.Instance.IsSecondary

if I'm reading the API doc correctly.

Upvotes: 1

Related Questions