MongoDB Data Backup Import Export

Source: Internet
Author: User
Tags json mongodb server port

(1) MongoDB Export (Mongoexport).

You can run the command by running:./mongoexport--help

./mongoexport--help Options:--help produce help message-v [--verbose] being more verbose (include multiple times for more verbosity e.g.-vvvvv)--version print th 
                            E program's version and Exit-h [--host] arg MONGO host to connect to (<set name>/s1,s2 for Sets)--port ARG server port. Can also use--host hostname:port--ipv6 enable IPV6 support (disabled by default)-U [--username ] Arg username-p [--password] arg password--dbpath arg directly access Mongod database files In the given path, instead of connecting to a Mongod server-n  Eeds to lock the data directory, so cannot being used if a mongod is currently accessing the same 
Path--DIRECTORYPERDB If dbpath specified, each db was in a separate                            Directory--journal enable journaling-d [--db] arg database t o use-c [--collection] arg collection to use (some commands)-F [--fields] arg comma separated list of fi
  Eld names e.g.-f name,age--fieldfile arg file with fields Names-1 per line -Q [--query] arg query filter, as a JSON string--csv export to CSV instead of Json-o [ --out] arg output file; 
                            If not specified, stdout are used--jsonarray output to a JSON array rather than one object per 
                            line-k [--slaveok] arg (=1) use secondaries for export if available, default True
Parameter description.

For example, I export a table in a database.

./mongoexport-h 127.0.0.1--port 27017-d upload-c video_encode_history-u uts-p u.l7a@bj-f MID,CREATETIME,IMGHTTPP Ath-q ' {vtype: "1", status:30,imghttppath:{"$ne": null}} '--csv-o History.txt


(2) MongoDB Import Tool Mongodimport

Run the help command:./mongoimport--help

Options:--help produce help message-v [--verbose] being more verbose (include multiple times
  For more verbosity e.g-VVVVV)--version print the program's version and exit -h [--host] arg MONGO host to connect to (<set name>/s1,s2 for sets)--port arg server por  T. Can also use--host hostname:port--ipv6 enable IPV6 support (disabled by default)-U [--username ] Arg username-p [--password] arg password--dbpath arg directly access Mongod database files in th e given path, instead of connecting to a Mongod server-needs to L Ock The data directory, so cannot was used if a mongod is currently accessing the same path--               Directoryperdb if dbpath specified, each db was in a separate directory--journal Enable Journaling-d [--DB] arg database to use-c [--collection] arg collection to use (some commands)-F [--fields] Arg comma separated list of field names e.g.-f name,age--fieldfile arg file with field names-1 per Lin e--ignoreblanks if given, empty fields in CSV and TSV would be ignored--type arg type of file T  o Import. Default:json (JSON,CSV,TSV)--file arg file to import from; If not specified stdin is used--drop drop collection first--headerline csv,tsv only-u SE first line as headers--upsert insert or update objects that already exist--upsertfields ARG c omma-separated fields for the query part of the Upsert. Should make sure this is indexed--stoponerror stop importing at first error rather than continuing--JS Onarray load a JSON array, not one item per line. 
                         Currently Limited to 4MB. 

Export command:/usr/local/mongodb/bin/mongoimport--username=uts--password=password-h 127.0.0.1--port 27017-d upload-c C_clou D Video.json

Connect remotely to other MongoDB machines:

/usr/local/mongodb/bin/mongo--username=uts--PASSWORD=U.L7A@BJ Host:port/upload

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.