OperationFailure: Authentication failed.
append /?authSource=admin’ to the end to the URI
Authentication Options
The following connection string to a replica set specifies the authSource to the admin database. That is the user credentials are authenticated to the admin database.
mongodb://myDBReader:D1fficultP%[email protected]:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/test?replicaSet=myRepl&authSource=admin
authSource
Specify the database name associated with the user’s credentials. authSource defaults to the database specified in the connection string.
For authentication mechanisms that delegate credential storage to other services, the authSource value should be $external as with the PLAIN (LDAP) and GSSAPI (Kerberos) authentication mechanisms.
MongoDB will ignore authSource values if the connection string specifies no username.
摘抄于 https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options