1

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

Return-1
  • 2,329
  • 3
  • 21
  • 56
Niko
  • 101
  • 2
  • 11

1 Answers1

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.

A. Jesse Jiryu Davis
  • 23,641
  • 4
  • 57
  • 70
  • Thanks for you answer! In other words, I have to execute `mongoimport` from the terminal and I cannot call it from within PyMongo? I ran it now from the command line but I was interested if there is something in PyMongo to accomplish the same. – Niko May 16 '17 at 13:03
  • Right, you have to execute mongoimport from the terminal. – A. Jesse Jiryu Davis May 16 '17 at 17:46
  • Thanks! That's all I wanted to know :) – Niko May 18 '17 at 13:00
  • @Niko you can always call `system("my_command_line_command")` in python – libby Nov 05 '20 at 17:44