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: /imports
read_only: true
healthcheck:
test: echo 'db.stats().ok' | mongo mongo --quiet
interval: 14s
timeout: 3s
retries: 3
start_period: 1s
Note: 🦄 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:
- root - means a root folder that you are going to bind to 🦄 container
- database_name - folder that represents a future or existing mongo database
- collection_name.json - JSON file that represents a future or existing mongo collection
Currently there are only 2 of them:
- MONGO_ADDRESS - address of your mongo instance
- RECREATE_COLLECTIONS - if set to true 🦄 will re-create the specified collection, otherwise it will just import the data.
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:
- Support for credentials
- Support for upsert