Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Cannot connect with authentication to mongodb?

There's another answer here: Can't connect to MongoDB with authentication enabled. I tried that but still can;t figure out what's wrong why my configuration.

I use Ubuntu 14.04, Mongo 3.4.1(latest) installed as a service

First after installation I run this command, just like its documentation here:

mongo --port 27017
use admin
db.createUser({user: "adminUser",pwd: "abc123",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})

it returns Successfully added user. Then I reconfigure the /etc/mongod.conf

storage:
   dbPath: /var/lib/mongodb
   journal:
     enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
  bindIp: 127.0.0.1

security:
  authorization: enabled

Save and restarted the mongod server : sudo service mongod restart

try to connect with: mongo -u "adminUser" -p "abc123" --authenticationDatabase "admin"

which is successfull, then if I change to another database with command use testDatabase, I cant make any operation to it.

use testDatabase
db.createCollection("people")

results:

{
    "ok" : 0,
    "errmsg" : "not authorized on testDatabase to execute command { create: \"people\" }",
    "code" : 13,
    "codeName" : "Unauthorized"
}

Here is registered users in my database

use admin
db.system.users.find()
{ "_id" : "admin.adminUser", 
  "user" : "adminUser", 
  "db" : "admin", 
  "credentials" : { "SCRAM-SHA-1" : {....} }, 
  "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ]
}

It seems that userAdminAnyDatabase role doesn't work anymore or is there anything wrong with my setup?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Built in roles UserAdmin & UserAdminAnyDatabase role allows you to create user and roles in database.

For read/ readWrite operations on database you have to create user with read/ readWrite role for that database.

Other option will be to add the role to the current user you have.

Something like this for example.

use test
db.createUser(
  {
    user: "myTester",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "test" },
             { role: "read", db: "reporting" } ]
  }
)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!