So we are having an interesting problem. We wanted to add authentication at the MongoDB Layer for more security. But we not getting a favorable outcome.
Pre-Setup
- Use mongo shell (against admin table) as root
- Switch to desired database (applicationdb)
- Execute db.createUser()
Validate user was created successfully
{ "_id" : "applicationdb.appuser", "user" : "appuser", "db" : "applicationdb", "roles" : [ { "role" : "readWrite", "db" : "applicationdb" } ] }
Scenario 1:
- Change mongodb.conf, auth=true
- Restart the Mongod service
Connect mongoose using:
mongoose.connect('mongodb://appuser:[email protected]:27017/applicationdb');
No errors received for connect, so try to perform a GET through Mongoose causes the operation to timeout without any error (at least that I could find)
Scenario 2:
- Change mongodb.conf, auth=false
- Restart the Mongod service
Connect mongoose using:
mongoose.connect('mongodb://xx.xxx.xxx.xxx:27017/applicationdb');
No errors received for connect, so try to perform a GET through Mongoose and it returns documents successfully
Why do we get this timeout and never a completed request when using authentication in MongoDB?
Any help would be great, we're at a loss on this one!