csv-2-mongo
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.
Note: CSV headers are required to correctly correlate MongoDB
fieldsto CSVfields.
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, --forceflag will overwrite the collection without a prompt. If the flag is omitted,csv-2-mongowill 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 mongo.travismclarke.com:27111
....................................
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, --forceflag.
$ csv-2-mongo -y -d animals -c mammals ./mammals.csv
....................................
Connecting to 0.0.0.0:27017
....................................
Import complete!
License
MIT © Travis Clarke
Metadata
Release files for csv-2-mongo 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| csv-2-mongo-0.0.2.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| csv_2_mongo-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.2 kB
Release files / csv-2-mongo-0.0.2.tar.gz
| Download URL | csv-2-mongo-0.0.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06079c4ccca83dcf86873ee9df6d06be03dd79ea7ad8e8f7b54a2164a9854787
|
|
BLAKE2b-256 checksum How to use checksums |
9f4d37b477577a396daf8e2244632f381734901fede53fe21326fd70075502b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / csv_2_mongo-0.0.2-py3-none-any.whl
| Download URL | csv_2_mongo-0.0.2-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
193a9fa71c81c22e9755a7a5b6ff5c0bca63e973392a4a6869e5572f1b8c1091
|
|
BLAKE2b-256 checksum How to use checksums |
2abf02a053619d5695bac05a3b86a930941687b3c47a2f24b8d7fd313050574a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|