MongoDB備份、還原、導(dǎo)出、導(dǎo)入、克隆操作示例
數(shù)據(jù)庫備份 – mongodump
備份本地所有MongoDB數(shù)據(jù)庫:
# mongodump -h 127.0.0.1 --port 27017 -o /root/db/alldb
備份遠程指定數(shù)據(jù)庫:
# mongodump -h 192.168.1.233 --port 27018 -d yourdb -o /root/db/yourdb
更多mongodump詳解
數(shù)據(jù)庫還原-mongorestore
恢復(fù)所有數(shù)據(jù)庫到MongoDB中:
# mongorestore -h 127.0.0.1 --port 27018 /root/db/alldb
還原指定數(shù)據(jù)庫:
# mongorestore --port 27017 -d yourdb /root/db/yourdb
更多mongorestore詳解
導(dǎo)出集合數(shù)據(jù)-mongoexport
導(dǎo)出數(shù)據(jù)庫中指定集合的數(shù)據(jù):
# mongoexport -h 192.168.1.233 --port 27018 -d yourdb -c yourcoll -o /root/yourcoll.json
導(dǎo)出集合中指定字段的數(shù)據(jù),導(dǎo)出的文件格式為csv:
# mongoexport -d yourdb -c test -f "id,name,score" --csv -o /root/test.csv
根據(jù)條件導(dǎo)出數(shù)據(jù):
# mongoexport -d yourdb -c yourcoll -q '{score:{$gt:80}}' -o /root/yourcoll-bk.json
更多mongoexport詳解
集合數(shù)據(jù)導(dǎo)入-mongoimport
還原導(dǎo)出的集合數(shù)據(jù):
# mongoimport -d yourdb -c yourcoll --file /root/yourcoll.json
導(dǎo)入集合數(shù)據(jù),插入或更新現(xiàn)有的數(shù)據(jù):
# mongoimport -d test -c yourcoll --file /root/yourcoll.json --upsert
更多mongoimport詳解
MongoDB數(shù)據(jù)庫克隆
命令格式:
db.copyDatabase(fromdb, todb, fromhost, username, password)
從遠程MongoDB中復(fù)制指定數(shù)據(jù)庫到本地:
# mongo
> db.copyDatabase("yii2", "lyii2", "192.168.0.69")
更多db.copyDatabase詳解
集合的克隆
命令格式:
db.runCommand({ cloneCollection: "<namespace>", from: "<hostname>", query: { <query> } });
從遠程MongoDB中克隆指定的集合到本地數(shù)據(jù)庫中:
# mongo
> db.runCommand({ cloneCollection: "test.user", from: "192.168.0.69", query:{} })
更多cloneCollection詳解
- 批量備份還原導(dǎo)入與導(dǎo)出MongoDB數(shù)據(jù)方式
- mongoDB4.2.8備份恢復(fù)與導(dǎo)出導(dǎo)入(推薦)
- MongoDB使用mongoexport和mongoimport命令,批量導(dǎo)出和導(dǎo)入JSON數(shù)據(jù)到同一張表的實例
- MongoDB 導(dǎo)出導(dǎo)入備份恢復(fù)數(shù)據(jù)詳解及實例
- 深入分析Mongodb數(shù)據(jù)的導(dǎo)入導(dǎo)出
- mongodb 數(shù)據(jù)庫操作--備份 還原 導(dǎo)出 導(dǎo)入
- 教你使用MongoDB導(dǎo)入導(dǎo)出備份數(shù)據(jù)
相關(guān)文章
分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù)的實踐詳解
這篇文章主要介紹了分布式文檔存儲數(shù)據(jù)庫之MongoDB備份與恢復(fù),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11
解決MongoDB6.0報錯:"mongo"不是內(nèi)部或外部命令,也不是可運行的程序或批處理文件
這篇文章主要給大家介紹了關(guān)于解決MongoDB6.0報錯:"mongo"不是內(nèi)部或外部命令,也不是可運行的程序或批處理文件的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-05-05
利用mongodb查詢某坐標(biāo)是否在規(guī)定多邊形區(qū)域內(nèi)的方法
這篇文章主要介紹了利用mongodb如何查詢某坐標(biāo)是否在固定多邊形區(qū)域內(nèi)的方法,文中給出了詳細示例代碼,相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-02-02
深入分析Mongodb數(shù)據(jù)的導(dǎo)入導(dǎo)出
這幾天想著公司要用MongoDB,自然就要用到數(shù)據(jù)導(dǎo)入導(dǎo)出,就自己學(xué)習(xí)了一下。本文介紹了mongoDb導(dǎo)入導(dǎo)出數(shù)據(jù)的方法,有需要的朋友參考下。2015-05-05

