First, Mongodump/mongorestore Way
Usage Scenario: Database Export specified collection, unable to manually modify the export file (binary)
Allowable condition: The original collection of the database can be deleted (processed: inserted) or retained (processed: deleted and then inserted)
Export Data format: binary type, not manually modified
1. Backing up the database specifies collection
c:\users\administrator>mongodump-d webdb-c Users-o E:\webdb_users_dump
Connected to:127.0.0.1
2014-05-08t07:23:42.047+0800 Database:webdb to E:\WEBDB_USERS_DUMP\WEBD
B
2014-05-08t07:23:42.053+0800 Webdb.users to e:\webdb_users_dump\webdb\users.b
Son
2014-05-08t07:23:42.084+0800 2 Documents
2014-05-08t07:23:42.084+0800 Metadata for Webdb.users to E:\webdb_users_dump\
Webdb\users.metadata.json
C:\users\administrator>
2. Recovering a Database collection
1). WebDB has been deleted before the users restore operation
c:\users\administrator>mongorestore-d webdb--directoryperdb E:\webdb_users_dum
P\webdb
Connected to:127.0.0.1
2014-05-08t07:36:39.530+0800 E:\webdb_users_dump\webdb\users.bson
2014-05-08t07:36:39.533+0800 going into namespace [webdb.users]
2 objects found
2014-05-08t07:36:39.536+0800 Creating index: {key: {_id:1}, Name: "_id_",
NS: "Webdb.users"}
C:\users\administrator>
2). WEBDB users before resuming operations are retained
c:\users\administrator>mongorestore-d webdb--drop--directoryperdb E:\webdb_us
Ers_dump\webdb
Connected to:127.0.0.1
2014-05-08t07:53:33.208+0800 E:\webdb_users_dump\webdb\users.bson
2014-05-08t07:53:33.210+0800 going into namespace [webdb.users]
2014-05-08t07:53:33.210+0800 dropping
2 objects found
2014-05-08t07:53:33.215+0800 Creating index: {key: {_id:1}, Name: "_id_",
NS: "Webdb.users"}
C:\users\administrator>
Second, the Mongoexport/mongoimport way
Use scenario: Export the database to specify collection, manually modify the export file (text) after resuming the update
Allowable Condition: The database original collection can be deleted before the import operation (processing mode: Insert) or reserved (process: Update)
Export Data format: text type, modifiable
1. Export Data and modify
c:\users\administrator>mongoexport-d webdb-c Users-o E:\users.json
Connected to:127.0.0.1
Exported 2 records
C:\users\administrator>
2. Import Modification Data
c:\users\administrator>mongoimport-d webdb-c Users--upsert--file E:\users.json
Connected to:127.0.0.1
2014-05-08t07:20:45.949+0800 Imported 2 objects
C:\users\administrator>
This article is from the "Yiyi" blog, make sure to keep this source http://heyiyi.blog.51cto.com/205455/1408178