Import data to MongoDB
If you want to import/restore or to do something else before using mongo db in your application, you can look at the following example.
You just need to create Dockerfile for mongo seed service and provide the command to prepare mongo db. In this case it’s command mongoimport
Dockerfile mongo_seed
FROM mongo
COPY init.json /init.json
CMD mongoimport --host mongodb --db exampleDb --collection contacts --type json --file /init.json --jsonArray
Looking around
In the root of this repository you’ll find a file named docker-compose.yml
.
Let’s quickly review the contents of this file:
docker-compose.yml
version: '3'
services:
mongodb:
image: mongo
command: mongod --smallfiles
ports:
- 27017
mongo_seed:
image: ${{mongo_seed}}
links:
- mongodb
client:
image: ${{build_prj}}
links:
- mongodb
ports:
- 9000
environment:
- MONGO_URI=mongodb:27017/exampleDb
You can add the following example to your GitHub or Bitbucket account, and build the example.