MongoDB run commands on a specific secondary node

337 Views Asked by At

I want to db.runCommand on a secondary node of a replica set, but not the primary (example).

What connection string should I use in mongosh to connect to it?

Connecting to the replica set (e.g. mongosh mongodb+srv://example.mongodb.net/) points me to the primary.

1

There are 1 best solutions below

3
C. Claudio On BEST ANSWER

a direct connection is required, i.e.

mongosh "mongodb://example-shard-00-02.web.mongodb.net:27017" \
   --tls \
   --authenticationDatabase admin \
   --username <user> --password <pwd>