From 33fed5a24b127277a81988ccd4f6bb531b2316ff Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Tue, 16 Feb 2021 14:10:18 +0100 Subject: [PATCH] Add list of options to mongoimport\export tools --- Database/MongoDB.md | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Database/MongoDB.md b/Database/MongoDB.md index 63835b8..1e274f7 100644 --- a/Database/MongoDB.md +++ b/Database/MongoDB.md @@ -158,37 +158,58 @@ db..drop() # delete whole collection db.dropDatabase() # delete entire database ``` -## Mongoimport Tool +## [Mongoimport](https://docs.mongodb.com/database-tools/mongoimport/) Utility to import all docs into a specified collection. If the collection alredy exists `--drop` deletes it before reuploading it. **WARNING**: CSV separators must be commas (`,`) ```sh -mongoimport -h –d –c --drop --jsonArray +mongoimport -mongoimport --host --ssl --username --password --authenticationDatabase admin --db --collection --type --file - -# if file is CSV and first line is header -mongoimport ... --haderline +--uri= +--host=<:port>, -h=<:port> +--username=, -u= +--password=, -p= +--collection=, -c= # Specifies the collection to import. +--ssl # Enables connection to a mongod or mongos that has TLS/SSL support enabled. +--type # Specifies the file type to import. DEFAULT: json +--drop # drops the collection before importing the data from the input. +--headerline # if file is CSV and first line is header +--jsonarray # Accepts the import of data expressed with multiple MongoDB documents within a single json array. MAX 16 MB ``` -## Mongoexport Tool +## [Mongoexport](https://docs.mongodb.com/database-tools/mongoexport/) Utility to export documents into a specified file. ```sh -mongoexport -h –d –c +mongoexport --collection= -mongoexport --host --ssl --username --password --authenticationDatabase admin --db --collection --type --out +--uri= +--host=<:port>, -h=<:port> +--username=, -u= +--password=, -p= +--db=, -d= +--collection=, -c= +--type= +--out=, -o= #Specifies a file to write the export to. DEFAULT: stdout +--jsonArray # Write the entire contents of the export as a single json array. +--pretty # Outputs documents in a pretty-printed format JSON. +--skip= +--limit= # Specifies a maximum number of documents to include in the export +--sort= # Specifies an ordering for exported results ``` -## Mongodump & Mongorestore +## [Mongodump][mongodump_docs] & [Mongorestore][mongorestore_docs] `mongodump` exports the content of a running server into `.bson` files. `mongorestore` Restore backups generated with `mongodump` to a running server. +[mongodump_docs]: https://docs.mongodb.com/database-tools/mongodump/ +[mongorestore_docs]: https://docs.mongodb.com/database-tools/mongorestore/ + ## Relations **Nested / Embedded Documents**: