Skip to content

Instantly share code, notes, and snippets.

@oxlb
Last active March 9, 2020 17:08
Show Gist options
  • Save oxlb/2c37f7ba3afea7174f2334202e3cc4b4 to your computer and use it in GitHub Desktop.
Save oxlb/2c37f7ba3afea7174f2334202e3cc4b4 to your computer and use it in GitHub Desktop.
Script to create mongoDB multiple database as well users
print('Start #################################################################');
db = db.getSiblingDB('api_prod_db');
db.createUser(
{
user: 'api_user',
pwd: 'api1234',
roles: [{ role: 'readWrite', db: 'api_prod_db' }],
},
);
db.createCollection('users');
db = db.getSiblingDB('api_dev_db');
db.createUser(
{
user: 'api_user',
pwd: 'api1234',
roles: [{ role: 'readWrite', db: 'api_dev_db' }],
},
);
db.createCollection('users');
db = db.getSiblingDB('api_test_db');
db.createUser(
{
user: 'api_user',
pwd: 'api1234',
roles: [{ role: 'readWrite', db: 'api_test_db' }],
},
);
db.createCollection('users');
print('END #################################################################');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment