问题
I found a command for mongodb which lets you import CSV files as a whole: https://docs.mongodb.com/manual/reference/program/mongoimport/
like this:
mongoimport --db users --type csv --headerline --file /opt/backups/contacts.csv
However, there seems to be no mention of this in Pymongo. Does it exists, and if so what is the syntax for it? Thanks in advance
回答1:
mongoimport
is a command-line program that you install. Instructions for installing MongoDB, including its tools like mongoimport
, are here:
https://docs.mongodb.com/manual/administration/install-community/
Once you've done that, execute mongoimport
from the Unix shell or Windows command prompt, whichever system you're on.
PyMongo is a Python driver for MongoDB, it allows you to write Python code that executes queries and commands on MongoDB over the network. PyMongo is separate from the MongoDB tools like mongoimport
.
来源:https://stackoverflow.com/questions/43999171/mongoimport-csv-with-pymongo