To reset the Docker environment (i.e. delete images and volumes)
- Ensure Docker containers are down
docker-compose down
- Delete all containers using the following command:
docker rm -f $(docker ps -a -q)
- Delete all volumes using the following command:
docker volume rm $(docker volume ls -q)
The MongoDB data is usually a jsonArray which cannot be imported via MongoExpress GUI The solution is to use mongoimport through the cli
- Download data
wget <DOWNLOAD_LINK>
- Move data to container. Using the same terminal where the MongoDB container was run, type the following:
docker cp <SOURCE_PATH> <MONGO_CONTAINER_NAME | MONGO_CONTAINER_ID>:<DESTINATION_PATH>
- execute the
mongoimport
command
Method 1: Exec
-
- a. Use the
exec
command to execute themongoimport
command in the container:
- a. Use the
docker exec <MONGO_CONTAINER_NAME | MONGO_CONTAINER_ID> mongoimport -h localhost:27017 -u <ADMIN_USERNAME> -p <ADMIN_PASSWORD> --authenticationDatabase=<CREDENTIALS_DB | admin> -d <DATABASE_NAME> -c <COLLECTION_NAME> --type json --file <FILE_NAME> --jsonArray
Method 2: Bash
-
- a. Access bash. Using the same terminal where the MongoDB container was run, type the following:
docker exec -it <MONGO_CONTAINER_NAME | MONGO_CONTAINER_ID> bash
-
- b Use
mongoImport
to import data with the following command:
- b Use
mongoimport -h localhost:27017 -u <ADMIN_USERNAME> -p <ADMIN_PASSWORD> --authenticationDatabase=<CREDENTIALS_DB | admin> -d <DATABASE_NAME> -c <COLLECTION_NAME> --type json --file <FILE_NAME> --jsonArray