欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MongoDB備份、還原、導(dǎo)出、導(dǎo)入、克隆操作示例

 更新時(shí)間:2015年07月04日 15:47:51   投稿:junjie  
這篇文章主要介紹了MongoDB備份、還原、導(dǎo)出、導(dǎo)入、克隆操作示例,本文分別給操作代碼、命令實(shí)例,需要的朋友可以參考下

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

備份本地所有MongoDB數(shù)據(jù)庫:

復(fù)制代碼 代碼如下:

# mongodump -h 127.0.0.1 --port 27017 -o /root/db/alldb

備份遠(yuǎn)程指定數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:

# mongodump -h 192.168.1.233 --port 27018 -d yourdb -o /root/db/yourdb

更多mongodump詳解

數(shù)據(jù)庫還原-mongorestore

恢復(fù)所有數(shù)據(jù)庫到MongoDB中:

復(fù)制代碼 代碼如下:

# mongorestore -h 127.0.0.1 --port 27018 /root/db/alldb

還原指定數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:

# mongorestore --port 27017 -d yourdb /root/db/yourdb

更多mongorestore詳解
導(dǎo)出集合數(shù)據(jù)-mongoexport

導(dǎo)出數(shù)據(jù)庫中指定集合的數(shù)據(jù):

復(fù)制代碼 代碼如下:

# mongoexport -h 192.168.1.233 --port 27018 -d yourdb -c yourcoll -o /root/yourcoll.json

導(dǎo)出集合中指定字段的數(shù)據(jù),導(dǎo)出的文件格式為csv:
復(fù)制代碼 代碼如下:

# mongoexport -d yourdb -c test -f "id,name,score" --csv -o /root/test.csv

根據(jù)條件導(dǎo)出數(shù)據(jù):
復(fù)制代碼 代碼如下:

# mongoexport -d yourdb -c yourcoll -q '{score:{$gt:80}}' -o /root/yourcoll-bk.json

更多mongoexport詳解

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

還原導(dǎo)出的集合數(shù)據(jù):

復(fù)制代碼 代碼如下:

# mongoimport -d yourdb -c yourcoll --file /root/yourcoll.json

導(dǎo)入集合數(shù)據(jù),插入或更新現(xiàn)有的數(shù)據(jù):
復(fù)制代碼 代碼如下:

# mongoimport -d test -c yourcoll --file /root/yourcoll.json --upsert

更多mongoimport詳解

MongoDB數(shù)據(jù)庫克隆

命令格式:

復(fù)制代碼 代碼如下:

db.copyDatabase(fromdb, todb, fromhost, username, password)

從遠(yuǎn)程MongoDB中復(fù)制指定數(shù)據(jù)庫到本地:
復(fù)制代碼 代碼如下:

# mongo
> db.copyDatabase("yii2", "lyii2", "192.168.0.69")

更多db.copyDatabase詳解
集合的克隆

命令格式:

復(fù)制代碼 代碼如下:

db.runCommand({ cloneCollection: "<namespace>", from: "<hostname>", query: { <query> } });

從遠(yuǎn)程MongoDB中克隆指定的集合到本地?cái)?shù)據(jù)庫中:
復(fù)制代碼 代碼如下:

# mongo
> db.runCommand({  cloneCollection: "test.user", from: "192.168.0.69", query:{}    })

更多cloneCollection詳解

相關(guān)文章

最新評論