最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MongoDB 導出導入備份恢復數(shù)據(jù)詳解及實例

 更新時間:2016年10月21日 09:46:25   投稿:lqh  
這篇文章主要介紹了MongoDB 導出導入備份恢復數(shù)據(jù)詳解及實例的相關資料,需要的朋友可以參考下

數(shù)據(jù)庫備份和數(shù)據(jù)恢復的重要性,我想大家都知道,這里就舉例說明如何操作數(shù)據(jù)備份,數(shù)據(jù)恢復的實例:

創(chuàng)建測試數(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ù)導出 mongoexport

參數(shù)說明:

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

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

例子:導出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"}

例子:導出user所有id到/tmp/user.csv

格式為csv但不指定字段會出錯

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ù)導入 mongoimport

參數(shù)說明:

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

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

導入前先清空collection user

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

例子:把上例導出的user.json導入

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

例子:把上例導出的user.csv導入

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ù)恢復 mongorestore

參數(shù)說明:

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

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

導入前先清空collection user

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

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

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

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • MongoDB操作類封裝實例代碼

    MongoDB操作類封裝實例代碼

    這篇文章主要給大家介紹了關于MongoDB操作類封裝的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用MongoDB具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-08-08
  • MongoDB數(shù)據(jù)備份遷移的全過程

    MongoDB數(shù)據(jù)備份遷移的全過程

    這篇文章主要記錄了MongoDB數(shù)據(jù)備份遷移的全過程,文中通過圖文結合的方式介紹的非常詳細,對大家了解學習MongoDB數(shù)據(jù)備份遷移有一定的幫助,需要的朋友可以參考下
    2024-06-06
  • MongoDB使用profile分析慢查詢的步驟

    MongoDB使用profile分析慢查詢的步驟

    這篇文章主要介紹了MongoDB profile分析慢查詢的示例,幫助大家更好的理解和學習使用MongoDB數(shù)據(jù)庫,感興趣的朋友可以了解下
    2021-04-04
  • 關于Mongodb參數(shù)說明與常見錯誤處理的總結

    關于Mongodb參數(shù)說明與常見錯誤處理的總結

    這篇文章主要給大家介紹了關于Mongodb參數(shù)說明與常見錯誤處理的相關資料,文中通過一步步的步驟介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編一起來學習學習吧。
    2017-07-07
  • 使用Locust對MongoDB進行負載測試的操作步驟

    使用Locust對MongoDB進行負載測試的操作步驟

    Locust是一款使用Python開發(fā)的開源性能測試工具,支持分布式,可在多臺主機上對系統(tǒng)持續(xù)發(fā)送請求,本文給大家介紹了使用Locust對MongoDB進行負載測試的操作步驟,文中通過圖文結合的方式介紹的非常詳細,需要的朋友可以參考下
    2025-01-01
  • MongoDB學習筆記之MapReduce使用示例

    MongoDB學習筆記之MapReduce使用示例

    這篇文章主要介紹了MongoDB學習筆記之MapReduce使用示例,本文直接給出實例代碼,需要的朋友可以參考下
    2015-07-07
  • mongodb eval 執(zhí)行服務器端腳本

    mongodb eval 執(zhí)行服務器端腳本

    在MongoDB的服務器端可以通過db.eval函數(shù)來執(zhí)行javascript腳本,如我們可以定義一個javascript函數(shù),然后通過db.eval在服務器端來運行!我們前面其實也接觸過在服務器段運行一個預定義的javascript腳本的情況,如在$where查詢,執(zhí)行mapreduce任務等。
    2015-05-05
  • Mongodb設置TTL索引自動清除數(shù)據(jù)與過期數(shù)據(jù)的方法

    Mongodb設置TTL索引自動清除數(shù)據(jù)與過期數(shù)據(jù)的方法

    今天小編就為大家分享一篇關于Mongodb設置TTL索引自動清除數(shù)據(jù)與過期數(shù)據(jù)的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • windows下安裝mongodb以及node.js連接mongodb實例

    windows下安裝mongodb以及node.js連接mongodb實例

    本篇文章主要介紹了windows下安裝mongodb以及node.js連接mongodb實例,非常具有實用價值,需要的朋友可以參考下
    2017-05-05
  • 解決mongo的tickets被耗盡導致卡頓問題

    解決mongo的tickets被耗盡導致卡頓問題

    這篇文章主要介紹了解決mongo的tickets被耗盡導致卡頓問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04

最新評論

灵璧县| 永昌县| 喀什市| 通许县| 孟村| 江都市| 万宁市| 吉安市| 吐鲁番市| 独山县| 漳浦县| 和林格尔县| 行唐县| 长子县| 蛟河市| 新昌县| 射阳县| 南皮县| 驻马店市| 通山县| 清丰县| 芦溪县| 海南省| 平乡县| 元阳县| 金秀| 肃南| 郴州市| 海兴县| 富顺县| 辽宁省| 天柱县| 天长市| 永春县| 卢龙县| 旺苍县| 伊金霍洛旗| 白沙| 北流市| 青铜峡市| 南城县|