Creating a MongoDB User

29 views
Skip to first unread message

do...@slice.com

unread,
Oct 8, 2014, 12:58:08 PM10/8/14
to mongod...@googlegroups.com
I am trying to automate the creation of a user in MongoDB.

The admin user was previously created.

I've tried this:

echo "use dbc" | mongo admin --verbose -u admin -p "password" create_app_user.js

where the create_app_user.js file contains:

db.createUser(
    {
      user: "dbc",
      pwd: "password",
      roles: [
         { role: "readWrite", db: "dbc" }
      ]
    }
)

However, that seems to create a dbc user in the admin database (not the dbc database), like this:

show users
...
{
"_id" : "admin.dbc",
"user" : "dbc",
"db" : "admin",
"roles" : [
{
"role" : "readWrite",
"db" : "dbc"
}
]
}

On the creation command, if I switch 'mongo admin' to 'mongo dbc' to instead connect to the dbc database, authentication fails... probably because the user doesn't exist yet.

How do I do this?

Doug.

Will Berkeley

unread,
Oct 8, 2014, 1:42:14 PM10/8/14
to mongod...@googlegroups.com
The authentication failing means the admin user can't authenticate to the dbc database. What roles does the admin user have?

-Will
Reply all
Reply to author
Forward
0 new messages