-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo-init.js
More file actions
25 lines (21 loc) · 759 Bytes
/
mongo-init.js
File metadata and controls
25 lines (21 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// mongo-init.js is the script that will be run when the container is started. https://stackoverflow.com/questions/63172735/mongodb-database-could-not-be-created-on-docker-container-startup
// Move to the admin database, always created by default: https://stackoverflow.com/a/68253550
db = db.getSiblingDB('admin');
// log in as the root user
db.auth('root', 'S3cr3tPFGDssw0rd');
// create and move to the new database
db = db.getSiblingDB('sample_mflix');
// create the user with read and write access
db.createUser({
user: 'dev',
pwd: 'S3cr3tPFGDdcv34',
roles: [
{
role: 'readWrite',
db: 'sample_mflix'
}
]
});
// create the collection
db.createCollection('movies');
db.createCollection('actors');