Reputation: 105
I use "mongoDB" image in docker-container. When I run command for export DB to csv:
docker exec -i 418f46e5595d mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone --out ./info.csv
File saved in folder where container is working. How can I save it on my machine?
Upvotes: 5
Views: 12851
Reputation: 3806
Other solutions are great, but just adding an alternative also:
docker-compose.yml - mount to local folder ./mongodb_data:/data/db
services:
mongo1:
volumes:
- ./mongodb_data:/data/db
export to relative mongo path - /data/db/info.csv - Will automatically populate into local folder - ./mongodb_data/info.csv
docker exec -i 418f46e5595d mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone --out "/data/db/info.csv";
Upvotes: 1
Reputation: 105
My decision:
1) export
docker exec -i 418f46e5595d mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone --out
./info.csv
2)copy to my machine
docker cp webspider_mongo_1:/data/info.csv .
Upvotes: 3
Reputation: 14015
remove the --out
option so it will export to stdout
and redirect output to a file, something like this:
docker exec -i 418f46e5595d mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone | gzip > info.csv
You might want to redirect error messages to a different stream, so:
docker exec -i 418f46e5595d mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone 2>/tmp/mongoexport.err | gzip > info.csv
Upvotes: 5