多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 數(shù)據(jù)庫 > 數(shù)據(jù)庫應(yīng)用 > MongoDB 導(dǎo)出導(dǎo)入備份恢復(fù)數(shù)據(jù)實(shí)例

MongoDB 導(dǎo)出導(dǎo)入備份恢復(fù)數(shù)據(jù)實(shí)例

來源:程序員人生   發(fā)布時(shí)間:2016-06-29 17:16:47 閱讀次數(shù):3262次

創(chuàng)建測(cè)試數(shù)據(jù)

創(chuàng)建db:testdb,collection:user,插入10條記錄

mongo MongoDB shell version: 3.0.2 connecting to: test > use testdb switched to db testdb > db.user.insert({id:1,name:"用戶1"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:2,name:"用戶2"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:3,name:"用戶3"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:4,name:"用戶4"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:5,name:"用戶5"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:6,name:"用戶6"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:7,name:"用戶7"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:8,name:"用戶8"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:9,name:"用戶9"}); WriteResult({ "nInserted" : 1 }) > db.user.insert({id:10,name:"用戶10"}); WriteResult({ "nInserted" : 1 }) > > db.user.find(); { "_id" : ObjectId("574d7aae8780832e6c4e27b4"), "id" : 1, "name" : "用戶1" } { "_id" : ObjectId("574d7aaf8780832e6c4e27b5"), "id" : 2, "name" : "用戶2" } { "_id" : ObjectId("574d7aaf8780832e6c4e27b6"), "id" : 3, "name" : "用戶3" } { "_id" : ObjectId("574d7aaf8780832e6c4e27b7"), "id" : 4, "name" : "用戶4" } { "_id" : ObjectId("574d7aaf8780832e6c4e27b8"), "id" : 5, "name" : "用戶5" } { "_id" : ObjectId("574d7aaf8780832e6c4e27b9"), "id" : 6, "name" : "用戶6" } { "_id" : ObjectId("574d7aaf8780832e6c4e27ba"), "id" : 7, "name" : "用戶7" } { "_id" : ObjectId("574d7aaf8780832e6c4e27bb"), "id" : 8, "name" : "用戶8" } { "_id" : ObjectId("574d7aaf8780832e6c4e27bc"), "id" : 9, "name" : "用戶9" } { "_id" : ObjectId("574d7ab08780832e6c4e27bd"), "id" : 10, "name" : "用戶10" }


數(shù)據(jù)導(dǎo)出 mongoexport

參數(shù)說明:

-d 數(shù)據(jù)庫-c collection名 -o 輸出的文件名 --type 輸出的格式,默許為json -f 輸出的字段,如果--type為csv,則需要加上 -f "字段名"

更多參數(shù)說明可參考 mongoexport –help

例子:導(dǎo)出user所有記錄到/tmp/user.json

mongoexport -d testdb -c user -o /tmp/user.json 2016-05-31T20:00:32.257+0800 connected to: localhost 2016-05-31T20:00:32.286+0800 exported 10 records cat /tmp/user.json {"_id":{"$oid":"574d7aae8780832e6c4e27b4"},"id":1,"name":"用戶1"} {"_id":{"$oid":"574d7aaf8780832e6c4e27b5"},"id":2,"name":"用戶2"} {"_id":{"$oid":"574d7aaf8780832e6c4e27b6"},"id":3,"name":"用戶3"} {"_id":{"$oid":"574d7aaf8780832e6c4e27b7"},"id":4,"name":"用戶4"} {"_id":{"$oid":"574d7aaf8780832e6c4e27b8"},"id":5,"name":"用戶5"} {"_id":{"$oid":"574d7aaf8780832e6c4e27b9"},"id":6,"name":"用戶6"} {"_id":{"$oid":"574d7aaf8780832e6c4e27ba"},"id":7,"name":"用戶7"} {"_id":{"$oid":"574d7aaf8780832e6c4e27bb"},"id":8,"name":"用戶8"} {"_id":{"$oid":"574d7aaf8780832e6c4e27bc"},"id":9,"name":"用戶9"} {"_id":{"$oid":"574d7ab08780832e6c4e27bd"},"id":10,"name":"用戶10"}

例子:導(dǎo)出user所有id到/tmp/user.csv

格式為csv但不指定字段會(huì)出錯(cuò)

mongoexport -d testdb -c user --type csv -o /tmp/user.csv 2016-05-31T20:01:05.393+0800 Failed: CSV mode requires a field list mongoexport -d testdb -c user --type csv -f "id" -o /tmp/user.csv 2016-05-31T20:01:46.510+0800 connected to: localhost 2016-05-31T20:01:46.534+0800 exported 10 records cat /tmp/user.csv id 1 2 3 4 5 6 7 8 9 10


數(shù)據(jù)導(dǎo)入 mongoimport

參數(shù)說明:

-d 數(shù)據(jù)庫-c collection名 --type 導(dǎo)入的格式,默許json -f 導(dǎo)入的字段名 --headerline 如果導(dǎo)入的格式是csv,則可使用第1行的標(biāo)題作為導(dǎo)入的字段 --file 要導(dǎo)入的文件

更多參數(shù)說明可參考 mongoimport –help

導(dǎo)入前先清空collection user

> db.user.drop(); true > db.user.find(); >

例子:把上例導(dǎo)出的user.json導(dǎo)入

mongoimport -d testdb -c user --file /tmp/user.json 2016-05-31T20:10:22.240+0800 connected to: localhost 2016-05-31T20:10:22.287+0800 imported 10 documents

例子:把上例導(dǎo)出的user.csv導(dǎo)入

mongoimport -d testdb -c user --type csv --headerline --file /tmp/user.csv 2016-05-31T20:11:28.975+0800 connected to: localhost 2016-05-31T20:11:29.003+0800 imported 10 documents


數(shù)據(jù)備份 mongodump

參數(shù)說明:

-d 數(shù)據(jù)庫-c collection名 -o 備份的文件路徑

更多參數(shù)說明可參考 mongodump –help

例子:把testdb的user備份到/tmp

mongodump -d testdb -c user -o /tmp 2016-05-31T20:18:25.813+0800 writing testdb.user to /tmp/testdb/user.bson 2016-05-31T20:18:25.818+0800 writing testdb.user metadata to /tmp/testdb/user.metadata.json 2016-05-31T20:18:25.849+0800 done dumping testdb.user


數(shù)據(jù)恢復(fù) mongorestore

參數(shù)說明:

-d 數(shù)據(jù)庫-c collection名

更多參數(shù)說明可參考 mongorestore –help

導(dǎo)入前先清空collection user

> db.user.drop(); true > db.user.find(); >

例子:把上例備份的數(shù)據(jù)恢復(fù)

mongorestore -d testdb -c user /tmp/testdb/user.bson 2016-05-31T20:21:23.050+0800 checking for collection data in /tmp/testdb/user.bson 2016-05-31T20:21:23.084+0800 reading metadata file from /tmp/testdb/user.metadata.json 2016-05-31T20:21:23.088+0800 restoring testdb.user from file /tmp/testdb/user.bson 2016-05-31T20:21:23.153+0800 restoring indexes for collection testdb.user from metadata 2016-05-31T20:21:23.156+0800 finished restoring testdb.user 2016-05-31T20:21:23.156+0800 done
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 亚洲欧美精品一区 | 超清高清欧美videos | 欧美久久综合性欧美 | 亚洲综合无码一区二区 | 手机看片久久高清国产日韩 | 天天综合亚洲国产色 | 全国男人的天堂网 | 免费xxx视频 | 国产美女无遮挡免费视频网站 | 国产精品午夜在线播放a | 国产精品嫩草免费视频 | 九一精品国产 | 欧美性xxxx巨大黑人猛 | 成人欧美在线视频 | 成人网在线观看 | 国产一精品一aⅴ一免费 | 国产成人精品久久二区二区 | 欧美色涩| 免费a一级毛片在线播放 | 最近最新免费中文字幕高清 | 中国黄色毛片 大片 | 网全大全黄 | 国产精品精品视频 | 国产片免费看 | 国产72av国片精品jk制服 | 国产精品视频在线观看 | 日本www高清免费视频观看 | 亚洲人成77777在线播放网站不卡 | 天堂在线www网亚洲 天堂在线xw | 亚洲欧洲自拍偷拍 | 最近免费中文字幕4 | 久草免费小视频 | 午夜手机福利视频 | 亚洲欧美精品一区二区 | 国产成人免费片在线观看 | 欧美日韩看片 | 波多野结衣在线免费观看视频 | 亚洲网视频 | 波多野结衣一区 | 狠狠躁夜夜躁人人躁婷婷视频 | 久久久久久久亚洲精品 |