Is it possible to get replica set status without admin permission

Hi,

I use mongocxx 3.6.1 for mongodb access in C++ app. Due to the db administration rules, the app connects to mongodb without the permission to admin db. The app needs to get the replica set info such as which server is primary and which is secondary. When the app calls { replSetGetStatus : 1 } by database::run_command(), the call fails with the error “not authorized on admin to execute command”.

I wonder if there is a way to get the replica set status without admin permission.

Thanks.

Hi @Yudong_Sun

The driver should handle this automatically for you. I have never used the C++ driver but this is a common idiom from the few drivers I have used.

Indeed the tutorial creates a connection using a mongodb uri:
http://mongocxx.org/mongocxx-v3/tutorial/#make-a-connection

The database command to get the topology(primary, members, some settings) is isMaster

MongoDB drivers and clients use isMaster to determine the state of the replica set members and to discover additional members of a replica set.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.