From df2ebc7b862a8b85e661cbf845c9ae4f870b91f7 Mon Sep 17 00:00:00 2001 From: Axel Navarro Date: Sun, 30 May 2021 10:20:00 -0300 Subject: [PATCH] mongoimport: add page (#6008) --- pages/common/mongoimport.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pages/common/mongoimport.md diff --git a/pages/common/mongoimport.md b/pages/common/mongoimport.md new file mode 100644 index 000000000..58a329109 --- /dev/null +++ b/pages/common/mongoimport.md @@ -0,0 +1,28 @@ +# mongoimport + +> Imports content from a JSON, CSV, or TSV file into a MongoDB database. +> More information: . + +- Import a JSON file into a specific collection: + +`mongoimport --file={{path/to/file.json}} --uri={{mongodb_uri}} --collection={{collection_name}}` + +- Import a CSV file, using the first line of the file to determine field names: + +`mongoimport --type={{csv}} --file={{path/to/file.csv}} --db={{database_name}} --collection={{collection_name}}` + +- Import a JSON array, using each element as a separate document: + +`mongoimport --jsonArray --file={{path/to/file.json}}` + +- 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,...}}"` + +- 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` + +- Display help: + +`mongoimport --help`