Containerized shell script for seed Mongo databases using JSON files.
898
A container based on offical mongo image with a purpose of making a data seeding simple and a part of your docker-compose setup. The emphasis is on the local environments, but I suppose that doesn't have to be a limit, but in production it is your responsibility!
Repo contains an example, but the snippet below sums it up:
unicorn:
image: unicorn:latest
container_name: unicorn.ctn
environment:
- MONGO_ADDRESS=mongo:27017
- RECREATE_COLLECTIONS=true
depends_on:
- mongo
volumes:
- type: bind
source: ./data
target: /unicorn/data
read_only: true
healthcheck:
test: echo 'db.stats().ok' | mongo mongo --quiet
interval: 14s
timeout: 3s
retries: 3
start_period: 1s
Note: :unicorn: container is dependent on mongo container and code for it was omitted for brevity sake.
You should put your json files in a folder on your local machine structured like:
root/database_name/collection_name.json
Where:
Currently there are only 2 of them:
This is a project I created because I found it useful in my day-2-day dev life, but also a way to play around with shell scripts. Having said that I am no expert when ti comes to writing shell scripts, and I am pretty sure that this one can be optimized or written more nicely, so I will appreciate all the comments.
Thanks to whom ever made the beautiful ASCII art!!!
Things that I would like to add in the future:
Content type
Image
Digest
Size
156.4 MB
Last updated
over 6 years ago
docker pull mirzamerdovic/unicorn