1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-05 01:35:25 +02:00
tldr/pages/common/mongoimport.md

29 lines
1.1 KiB
Markdown
Raw Normal View History

2021-05-30 10:20:00 -03:00
# mongoimport
> Imports content from a JSON, CSV, or TSV file into a MongoDB database.
> More information: <https://docs.mongodb.com/database-tools/mongoimport/>.
- Import a JSON file into a specific collection:
`mongoimport --file {{path/to/file.json}} --uri {{mongodb_uri}} {{[-c|--collection]}} {{collection_name}}`
2021-05-30 10:20:00 -03:00
- Import a CSV file, using the first line of the file to determine field names:
`mongoimport --type {{csv}} --file {{path/to/file.csv}} {{[-d|--db]}} {{database_name}} {{[-c|--collection]}} {{collection_name}}`
2021-05-30 10:20:00 -03:00
- Import a JSON array, using each element as a separate document:
`mongoimport --jsonArray --file {{path/to/file.json}}`
2021-05-30 10:20:00 -03:00
- Import a JSON file using a specific mode and a query to match existing documents:
`mongoimport --file {{path/to/file.json}} --mode {{delete|merge|upsert}} --upsertFields "{{field1,field2,...}}"`
2021-05-30 10:20:00 -03:00
- Import a CSV file, reading field names from a separate CSV file and ignoring fields with empty values:
`mongoimport --type {{csv}} --file {{path/to/file.csv}} --fieldFile {{path/to/field_file.csv}} --ignoreBlanks`
2021-05-30 10:20:00 -03:00
- Display help:
`mongoimport --help`