Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarjarapu/235c8d7abe248e4c4fd05b7b14abe0a0 to your computer and use it in GitHub Desktop.
Save sarjarapu/235c8d7abe248e4c4fd05b7b14abe0a0 to your computer and use it in GitHub Desktop.
A bash script to create a user with readWrite role on the social database
mongo admin --port 28000 -u user -p password --authenticationDatabase admin <<EOF
db.createUser({user: 'app_user', pwd: 'password', roles: [{role: 'readWrite', db: 'social'}]})
EOF
# The output of above command
# MongoDB shell version v3.6.2
# connecting to: mongodb://127.0.0.1:28000/
# MongoDB server version: 3.6.2
# Successfully added user: {
# "user" : "app_user",
# "roles" : [
# {
# "role" : "readWrite",
# "db" : "social"
# }
# ]
# }
# bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment