I am using this connection uri to connect to mongodb: mongodb://user:password@localhost/admin
. It will use admin
as bot authentication and target database. How can I make the uri to use admin
as authentication but allow me to connect to a different database? Please see below command as an example:
mongo --host localhost -u user -p password --authentication admin test
the above command will use admin
as the authentcation database but connect to test
database. how can I do the same thing on uri?
Best Answer
Yes.. Easily!
You put your destination DB at end of "base" string and add authentication db to parameter authSource