Skip to content

Commit

Permalink
add mongo init script
Browse files Browse the repository at this point in the history
  • Loading branch information
ocakhasan committed Nov 9, 2023
1 parent d35b870 commit e2c7634
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ services:
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: pass
MONGO_INITDB_DATABASE: test
MONGO_INITDB_DATABASE: test
volumes:
- ./docker-entrypoint-initdb.d/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
54 changes: 54 additions & 0 deletions docker-entrypoint-initdb.d/mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
db = db.getSiblingDB('test');

db.createCollection('posts');
db.createCollection('comments');

db.posts.insertMany([
{
"author": {
"id": 1,
"name": "Dostoyevski"
},
"likes": 12,
"title": "Crime and Punishment"
},
{
"author": {
"id": 1,
"name": "Dostoyevski"
},
"likes": 100,
"title": "Notes From The Underground"
},
{
"author": {
"id": 2,
"name": "Marcus Aurelius"
},
"likes": 200,
"title": "Meditations"
}
]);

db.comments.insertMany([
{
"comment": "great read",
"likes": 3,
"postTitle": "Crime and Punishment"
},
{
"comment": "good info",
"likes": 0,
"postTitle": "Notes From The Underground"
},
{
"comment": "I liked this post",
"likes": 12,
"postTitle": "Notes From The Underground"
},
{
"comment": "very nice book",
"likes": 8,
"postTitle": "Meditations"
}
])
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ first create the mongo database.
docker-compose up -d mongo
```

It will generate a new MongoDB container and populate the collections with some data.

then run

```bash
Expand Down

0 comments on commit e2c7634

Please sign in to comment.