I have a problem with MongoClient throwing error. Have ReplicaSet here, and auth has been enabled for db level.
My connection string looks like this:
mongodb://user:pass@server1:27017,server2:27017/dbname?w=majority&replicaSet=rs&readPreference=secondary
When I try to read data, I get exception
AssertionError: null == "unauthorized db:dbname ns:dbname.collection lock type:0 client:<ip.address>"
With readPreference=primary or readPreference=primaryPreferred it works just fine, so problem must be with authenticating against secondary.
When I try to pass user and pass for second server, I simply get AssertionError: null == {"name":"MongoError","errmsg":"auth fails","ok":0}
I sure can read data from both servers when I log in with mongo client from the app machine.
1. What is the correct Connection string for RS with Auth?
2. Can MongoClient automatically find all RS members and do read from secondaries?
Thank you in advance,