Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb user authentication

db.addUser({ user: "Carlos",
  pwd: "pwd",
  customData: { employeeId: 12345 },
  roles: [
    { role: "clusterAdmin", db: "admin" },
    { role: "readAnyDatabase", db: "admin" },
    "readWrite"
  ]
})

This is an example setup script in mongo wiki http://docs.mongodb.org/manual/reference/method/db.addUser/

Whats wrong with this script... I am getting

{
    "user" : "Carlos",
    "pwd" : "ccb9d76967dcb0315ab62e88cb5c372b",
    "customData" : {
        "employeeId" : 12345
    },
    "roles" : [
        {
            "role" : "clusterAdmin",
            "db" : "admin"
        },
        {
            "role" : "readAnyDatabase",
            "db" : "admin"
        },
        "readWrite"
    ],
    "_id" : ObjectId("5444963f3507d43d2138fa6f")
}

uncaught exception: couldn't add user: Roles must be non-empty strings.

like image 305
james007 Avatar asked Jan 09 '23 14:01

james007


1 Answers

This works in Mongo 2.4.5

db.addUser({ user: "dbOwner",  pwd: "dbOwner", roles: [ "dbOwner", "DBNAME" ]})
like image 85
james007 Avatar answered Jan 18 '23 00:01

james007