Skip to main content

Import a CSV to MongoDB.

Project description

csv-2-mongo

PyPi release Downloads

Import a CSV to MongoDB using Python 🐍.

Installation

$ pip install csv-2-mongo

Usage

Usage: csv_2_mongo.py [OPTIONS] FILE

  Import a csv FILE to MongoDB

Options:
  -h, --help             Show this message and exit.
  -v, --version          Show the version and exit.
  -d, --database name    Database name.  [default: test]
  -c, --collection name  Collection name.  [default: test]
  -H, --host host        Host name.  [default: 0.0.0.0]
  -p, --port port        Port number.  [default: 27017]
  -t, --timeout sec      Connection timeout (seconds).  [default: 5]
  -f, --force            Overwrite collection if exists.
  -y, --yes              Automatic yes to prompts.

Examples

Import mammals.csv to a mammals collection in the animals database:

$ csv-2-mongo -d animals -c mammals ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................

Import data.csv to database=animals collection=mammals [y/N]? y
Import complete!

Import mammals.csv to a mammals collection in the animals database overwriting the collection if it exists:

Note: the -f, --force flag will overwrite the collection without a prompt. If the flag is omitted, csv-2-mongo will prompt you before operations with potential data loss.

$ csv-2-mongo -f -d animals -c mammals ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................

Import data.csv to database=animals collection=mammals [y/N]? y
Import complete!

Import mammals.csv to a mammals collection in the animals database running on host mongo.travismclarke.com at port 27111:

$ csv-2-mongo -d animals -c mammals -H mongo.travismclarke.com -p 27111 ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................

Import data.csv to database=animals collection=mammals [y/N]? y
Import complete!

To skip the prompt (e.g. Import data.csv to ...), such as running via a script, one can pass the -y, --yes flag to force a yes response to the confirmation prompt:

Note: this will not suppress the overwrite prompt which still requires the -f, --force flag.

$ csv-2-mongo -y -d animals -c mammals ./mammals.csv
....................................
Connecting to 172.24.194.133:27017
....................................

Import complete!

License

MIT © Travis Clarke

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv-2-mongo-0.0.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

csv_2_mongo-0.0.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file csv-2-mongo-0.0.1.tar.gz.

File metadata

  • Download URL: csv-2-mongo-0.0.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for csv-2-mongo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6d0da140113e302cf17f661686e93f9849b22b665381bc6827faae64b181e38b
MD5 49218f6074c593d84351de2d6ce76326
BLAKE2b-256 7388b7bc40606baae63d3feebae7a4ab2ce3bba46b62b2f36a01345dd016aadd

See more details on using hashes here.

File details

Details for the file csv_2_mongo-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: csv_2_mongo-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for csv_2_mongo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccfe2d9fd1d76df3bb8d2af33773ea733f475fb34aed0034738aeda38a0c14a0
MD5 dad30e491fb26d931937733b75d786e6
BLAKE2b-256 e10481ed55fd8c878281bc99c754c8e7cb81aa14f68195c530d8b875fbdfb7ea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page