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 of installing a script in the mongo wiki http://docs.mongodb.org/manual/reference/method/db.addUser/

What's wrong with this script ... I get

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

uncaught exception: failed to add user: roles must be nonempty.

+4
source share
1 answer

This works in Mongo 2.4.5

db.addUser({ user: "dbOwner",  pwd: "dbOwner", roles: [ "dbOwner", "DBNAME" ]})
+5
source

All Articles