NOTE: I have tried not setting bind_ip
and also setting it to 0.0.0.0
-- neither one fixed my issue.
This is my mongod.conf
file:
systemLog:
destination: file
path: "/root/mongodb.log"
logAppend: true
net:
port: 25015
processManagement:
fork: true
setParameter:
enableLocalhostAuthBypass: true
storage:
dbPath: /root/mongo_data
engine: wiredTiger
The first thing I did was SSH in to the DigitalOcean droplet where it is running and do the following:
mongo --port 25019
I was able to connect, so I know it picked up the options in the mongod.conf
file.
The second thing I did was issue the following command:
> use admin; switched to db admin > db.createUser( { user: "siteUserAdmin", pwd: "eqt-dfts-mad-ghbr-ovd-g", roles: [{role: "userAdminAnyDatabase", db: "admin"}] } ) Successfully added user: { "user" : "siteUserAdmin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }
So that was apparently a success!
Next I exited from the mongo shell and then logged in to the mongo shell again as
siteUserAdmin
with credential from above.Then I created a user and a database for the app I'm building:
> use MyDatabase; switched to db MyDatabase > db.createUser( { user: "my_user", pwd: "cu-npp-re-jpor-mtw-e-s", roles: [ {role: "readWrite", db: "MyDatabase"}, {role: "dbAdmin", db: "MyDatabase"} ] } ) Successfully added user: { "user" : "vantage", "roles" : [ { "role" : "readWrite", "db" : "AdVantage" }, { "role" : "dbAdmin", "db" : "AdVantage" } ] }
So that was also apparently a success!
I then exited the mongo shell and then logged in to the mongo shell again as
my_user
with credentials from (4). I confirmed that I was able to create a collection calleddemotest
inMyDatabase
:> use MyDatabase; switched to db MyDatabse > db.createCollection("demotest") { "ok" : 1 } > show collections; demotest > show dbs; MyDatabase 0.000GB admin 0.000GB local 0.000GB > exit bye
So far so good.
I then switched to a terminal on my local machine. My goal is to be able to connect to this MongoDB instance from my local machine and from an app that is running somewhere else on the internet. So I issued the following command on my local machine:
PROMPT> mongo --host 102.216.73.164 -u my_user -p cu-npp-re-jpor-mtw-e-s --authenticationDatabase MyDatabase --port 25019 MongoDB shell version: 2.6.6 connecting to: 102.216.73.164:25019/test 2015-05-13T21:03:18.963-0400 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210 exception: login failed
Here is what I don't understand:
why did it try to connect to the
test
database?why doesn't it work?