-
Notifications
You must be signed in to change notification settings - Fork 65
/
init-mongo.sh
59 lines (55 loc) · 1.69 KB
/
init-mongo.sh
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
## Set new user to database
mongosh $MONGO_DB -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --eval "db.createUser({ user: '$MONGO_DB_USERNAME', pwd: '$MONGO_DB_PASSWORD', roles: [{ role: 'readWrite', db: '$MONGO_DB'}]})" --authenticationDatabase admin
## Seed Users and Contacts into database
mongosh $MONGO_DB <<EOF
var rootUser = '$MONGO_INITDB_ROOT_USERNAME';
var rootPassword = '$MONGO_INITDB_ROOT_PASSWORD';
var admin = db.getSiblingDB('$MONGO_INITDB_DATABASE');
admin.auth(rootUser, rootPassword);
db.users.drop();
db.users.insertMany([
{
"_id": ObjectId("6759daeb097c7d69426b7649"),
"create_date": new Date("2024-12-11T19:29:19.895Z"),
"username": "[email protected]",
"email": "[email protected]",
"password": "\$2a\$10\$nc0yO2eeCDOLg6sObsAHfuXQY8NnCrhHz5GbkmPYsAGLsQoSZa.qm",
"firstName": "NItin",
"lastName": "Singh"
}
]);
db.contacts.drop();
db.contacts.insertMany([
{
"_id": ObjectId("6759daeb097c7d69426b7641"),
"firstName": "Nitin",
"lastName": "Singh",
"mobile": "9876543243",
"email": "[email protected]",
"city": "Mumbai",
"postalCode": "421201",
"create_date": new Date()
},
{
"_id": ObjectId("6759daeb097c7d69426b7650"),
"firstName": "Sachin",
"lastName": "Singh",
"mobile": "9876540000",
"email": "[email protected]",
"city": "Pune",
"postalCode": "421201",
"create_date": new Date()
},
{
"_id": ObjectId("6759daeb097c7d69426b7651"),
"firstName": "Vikram",
"lastName": "Singh",
"mobile": "9876540000",
"email": "[email protected]",
"city": "Pune",
"postalCode": "421201",
"create_date": new Date()
}
]);
EOF