標籤:
匯入匯出use hndb;
db.s.save({name:‘李四‘,age:18,score:80,address:‘鄭州‘});db.s.save({name:‘李三‘,age:8,score:50,address:‘鄭州‘});db.s.save({name:‘張三‘,age:38,score:20,address:‘天津‘});db.s.save({name:‘趙六‘,age:28,score:70,address:‘鄭州‘});db.s.save({name:‘王五五‘,age:19,score:90,address:‘北京‘});
只匯出name欄位舊 mongoexport localhost:27017/admin -d hndb -c s -u admin -p admin -o c:\s.json -f name
新 只匯出name,agemongoexport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s /o c:\j.js /f name,age
匯出所有屬性mongoexport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s /o c:\j.js
資料匯入舊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
刪除資料庫,db.dropDatabase();備份與恢複匯出協助到本地
F:\mongodb\bin>mongodump.exe --help >f:/mongodump-help.txt
F:\mongodb\bin>mongorestore.exe --help >f:/mongorestore-help.txt
備份mongodump /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /o c:/
備份指定庫指定表 hndb 集合s 壓縮備份mongodump /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /c s /o c:/ /gzip
備份指定庫指定表 hndb 所有資訊 備份到c:/hndb.zip檔案中mongodump /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
恢複mongorestore /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /dir c:/hndb/
恢複指定的備份,gzip格式mongorestore /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip
恢複 hndb 所有資訊 從檔案c:/hndb.zipmongorestore /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
資料庫的匯出
F:\mongodb\bin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
tionDatabase:admin /d hndb /o c:/
刪除表> db.book.drop();true刪除庫> db.dropDatabase();{ "dropped" : "hndb", "ok" : 1 }刪除庫表,然後備份恢複
F:\mongodb\bin>mongorestore /h localhost /port 27017 /u admin /p admin /authent
icationDatabase:admin /d hndb /dir c:/hndb/
壓縮檔的匯出
備份指定庫指定表 hndb 所有資訊 備份到c:/hndb.zip檔案中
mongodump /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
刪除庫表,壓縮檔的匯入
恢複 hndb 所有資訊 從檔案c:/hndb.zip
mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
只匯出stu壓縮檔到hndb裡面
F:\mongodb\bin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
tionDatabase:admin /d hndb /c stu /o c:/ /gzip
恢複指定的備份,gzip格式
恢複指定的備份,gzip格式
mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip
來自為知筆記(Wiz)
mongodb 的備份恢複匯入與匯出