MongoDB Backup recovery Import and export

Source: Internet
Author: User
Tags mongodump mongorestore

Import and export use HNDB;
Db.s.save ({name: ' John Doe ', age:18,score:80,address: ' Zhengzhou '});d B.s.save ({name: ' Lie Triple ', age:8,score:50,address: ' Zhengzhou '}); Db.s.save ({name: ' Zhang San ', age:38,score:20,address: ' Tianjin ');d b.s.save ({name: ' Zhao Liu ', age:28,score:70,address: ' Zhengzhou '}); Db.s.save ({name: ' King 55 ', age:19,score:90,address: ' Beijing '});

Export only Name field old Mongoexport localhost:27017/admin-d hndb-c s-u admin-p admin-o c:\s.json-f Name
New only export name,agemongoexport/h localhost/port 27017/authenticationdatabase:admin/u admin/p admin/d hndb/c s/o c:\j.js /F Name,age
Export All Properties mongoexport/h localhost/port 27017/authenticationdatabase:admin/u admin/p admin/d hndb/c s/o c:\j.js

Data import old mongoimport-d shop-c student-u user-p shop--directoryperdb C:\student.json
mongoimport/h localhost/port 27017/authenticationdatabase:admin/u admin/p admin/d hndb/c s C:\j.js
Delete database, db.dropdatabase (); Backup and restore export help to local
  
 
  1. F:\mongodb\bin>mongodump.exe --help >f:/mongodump-help.txt
  2. F:\mongodb\bin>mongorestore.exe --help >f:/mongorestore-help.txt


Backup mongodump/h localhost/port 27017/u admin/p 123/authenticationdatabase:admin/d hndb/o c:/
Backing up the specified library specifies the table HNDB collection s compressed backup mongodump/h localhost/port 27017/u admin/p 123/authenticationdatabase:admin/d hndb/c s/o C: //gzip

Backing up the specified library specifies the table hndb all information back to the C:/hndb.zip file mongodump/h localhost/port 27017/u admin/p 123/authenticationdatabase:admin/d H Ndb/archive:c:/hndb.zip
Recovery mongorestore/h localhost/port 27017/u admin/p 123/authenticationdatabase:admin/d hndb/dir c:/hndb/
Restore the specified backup, gzip format mongorestore/h localhost/port 27017/u admin/p 123/authenticationdatabase:admin/d hndb/dir:c:/hndb// Gzip
Recover hndb All information from file c:/hndb.zipmongorestore/h localhost/port 27017/u admin/p 123/authenticationdatabase:admin/d hndb/a Rchive:c:/hndb.zip


Export of databases
  
 
  1. F:\mongodb\bin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
  2. tionDatabase:admin /d hndb /o c:/


Delete Table > Db.book.drop (); True Delete library > db.dropdatabase (); {"Dropped": "Hndb", "OK": 1} Delete the library table, then back up the recovery
  
 
  1. F:\mongodb\bin>mongorestore /h localhost /port 27017 /u admin /p admin /authent
  2. icationDatabase:admin /d hndb /dir c:/hndb/
Export of compressed files
  
 
  1. 备份指定库指定表 hndb 所有信息 备份到c:/hndb.zip文件中
  2. mongodump /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
Delete a library table, import a compressed file
  
 
  1. recovery hndb All information From file c :/ hndb . zip
  2. mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
Export only Stu compressed files into hndb
  
 
  1. F : \mongodb\b in > mongodump / h localhost / port 27017 / u admin / Span class= "PLN" >p admin / authentica
  2. tionDatabase:admin /d hndb /c stu /o c:/ /gzip
Restores the specified backup, gzip format
  
 
  1. 恢复指定的备份,gzip格式
  2. mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip





From for notes (Wiz)

MongoDB Backup recovery Import and export

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.