Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb getting error while creating new user

Tags:

I just installed a fresh mongodb on Ubuntu server and when i try to adduser i am getting error

db.createUser(
  {
    user: "admin",
    pwd: "ADYkdfd332@@33",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)


2018-07-03T13:29:41.556+0530 E QUERY    [thread1] Error: couldn't add user: Use of SCRAM-SHA-256 requires undigested passwords :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1
like image 489
Khanakia Avatar asked Jul 03 '18 08:07

Khanakia


People also ask

How do you create a new MongoDB user?

In MongoDB, users are created using createUser() method. This method creates a new user for the database, if the specified user is already present in the database then this method will return an error.

Which command can be used to create a user in MongoDB?

createUser() on the $external database to create users who have credentials stored externally to MongoDB.

How do I give permission to full user in MongoDB?

MongoDB: db. grantRolesToUser() method is used to grants an additional role and its privileges to a user. The name of the user to whom to grant roles. An array of additional roles to grant to the user. The level of write concern for the modification.


2 Answers

This works for me:

db.createUser({  
 user:"test1",
 pwd:"test1",
 roles:[  
  {  
     role:"readWrite",
     db:"u8"
  }
 ],
 mechanisms:[  
  "SCRAM-SHA-1"
 ]
})
like image 190
user9681090 Avatar answered Sep 21 '22 00:09

user9681090


If you use User Management Methods you have to set param passwordDigestor.

 db.createUser(
  {
    user: "admin",
    pwd: "ADYkdfd332@@33",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ],
    passwordDigestor: "<server|client>"
  }
)
like image 42
Dolynskiy Eduard Avatar answered Sep 20 '22 00:09

Dolynskiy Eduard