I have a scrapping python project which stored pandas data frame in a csv file. I setup docker run mongo but cant figure out how to store the data of csv file in mongodb. Do I have to copy the file in a specific location? and then try to import. I have tried mongoimport db.insert nothing seems to work
2
Answers
file-path
docker-container-hash
:/tmp
docker exec -it docker-container-hash bash
cd tmp
# Because file copied is located heremongoimport --db DB_Name --collection Collection_Name --type csv --headerline --file Name-of-file-to-import
To import CSV file to a running mongodb cluster:
The CSV file should be local to the mongoimport command, this means if you are running this command on your local computer then the file should be local as well and you just specify path to the file + filename.
If the
mongoimport
command is in the docker container, then you need to usedocker cp
command to copy the CSV file inside the container, and give the path to the CSV file in the container to themongoimport
command which will also be executed inside the container.mongoimport
command arguements: