Skip to content

Instantly share code, notes, and snippets.

@mersanuzun
Created December 11, 2017 12:29
Show Gist options
  • Save mersanuzun/1cf0e659217bfec20911bda6d5d78d61 to your computer and use it in GitHub Desktop.
Save mersanuzun/1cf0e659217bfec20911bda6d5d78d61 to your computer and use it in GitHub Desktop.
Create user and index in Mongodb
#!/bin/bash
# Set variables
USERNAME=$MONGODB_USERNAME
PASSWORD=$MONGODB_PASSWORD
DB_NAME=$MONGODB_DBNAME
# Create User
mongo $DB_NAME --eval "db.createUser({user: '$USERNAME',pwd: '$PASSWORD',roles: [{role: 'readWrite',db: '$DB_NAME'}]});"
# Create Index
mongo $DB_NAME --eval "db.someCollection.createIndex({'nsA': 1, 'nsB': 1, 'counterValue': 1});"
# Create index
mongo $DB_NAME --eval "db.someCollection2.createIndex({'ns': 1, 'js': 1})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment