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.