Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda