1

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

  1. Use mongo shell (against admin table) as root
  2. Switch to desired database (applicationdb)
  3. Execute db.createUser()
  4. Validate user was created successfully

    { "_id" : "applicationdb.appuser", "user" : "appuser", "db" : "applicationdb", "roles" : [ { "role" : "readWrite", "db" : "applicationdb" } ] }

Scenario 1:

  1. Change mongodb.conf, auth=true
  2. Restart the Mongod service
  3. Connect mongoose using:

    mongoose.connect('mongodb://appuser:password@xx.xxx.xxx.xxx:27017/applicationdb');

  4. 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:

  1. Change mongodb.conf, auth=false
  2. Restart the Mongod service
  3. Connect mongoose using:

    mongoose.connect('mongodb://xx.xxx.xxx.xxx:27017/applicationdb');

  4. 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!

Kyle
  • 2,339
  • 10
  • 33
  • 67

1 Answers1

1

You need to restart the mongo service with the --auth option see here

If it doesn't works do this: Try setting server options in mongoose with keepAlive set. See here and here.

Community
  • 1
  • 1
line-segment
  • 369
  • 5
  • 14