Reputation: 643
I'm currently trying to connect my nodejs app to mongodb on the same droplet.
I currently have auth = true
and droplet ip to the bind address and allowed my public ip to the ufw port connections.
This does allow me to remote in to my droplet from mongo compass.
The issue I'm having is this:
Let's say this is my connection string: mongodb://user:pass@droplet-ip:27017/DB-NAME
That connection string works fine on remote.
When I add my connection string to my nodejs app, something like this: mongodb://user:[email protected]:27017/DB-NAME
it doesn't connect.
But when I do mongodb://user:[email protected]:27017/
without specifying the DB-NAME it does connect.
I did create an admin account using the following methods:
use admin
db.createUser({user: "user", pwd: "password", roles: ["root"]});
If I use admin
and do a db.getUsers();
I get :
users:
[ { _id: 'admin.user',
user: 'user',
db: 'admin',
roles:
[ { role: 'userAdminAnyDatabase', db: 'admin' },
{ role: 'readWriteAnyDatabase', db: 'admin' } ] } ],
ok: 1
Any help figuring this out would be greatly appreciated.
Upvotes: 0
Views: 687
Reputation: 643
Well it just took a little more testing. Ended up being that I was suppose to include ?authSource=admin
to the end of the connection string.
Upvotes: 1