溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

DBA應(yīng)用技巧中怎樣利用MySQL技能學(xué)習(xí)MongoDB

發(fā)布時間:2021-09-29 10:35:47 來源:億速云 閱讀:114 作者:柒染 欄目:數(shù)據(jù)庫

DBA應(yīng)用技巧中怎樣利用MySQL技能學(xué)習(xí)MongoDB,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

1、MongoDB導(dǎo)入和導(dǎo)出
  (1)、mongoexport導(dǎo)出工具
  MongoDB提供了mongoexport工具,可以把一個collection導(dǎo)出成json格式或csv格式的文件??梢灾付▽?dǎo)出哪些數(shù)據(jù)項,也可以根據(jù)給定的條件導(dǎo)出數(shù)據(jù)。工具幫助信息如下:

雙擊代碼全選
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26[root@localhost bin]# ./mongoexport --helpoptions:   --help                  produce help message   -v [ --verbose ]        be more verbose (include multiple times for more                           verbosity e.g. -vvvvv)   -h [ --host ] arg       mongo host to connect to ( <set name>/s1,s2 for sets)   --port arg              server port. Can also use --host hostname:port   --ipv6                  enable IPv6 support (disabled by default)   -u [ --username ] arg   username   -p [ --password ] arg   password   --dbpath arg            directly access mongod database files in the given                           path, instead of connecting to a mongod  server -                           needs to lock the data directory, so cannot be used                           if a mongod is currently accessing the same path   --directoryperdb        if dbpath specified, each db is in a separate                           directory   -d [ --db ] arg         database to use   -c [ --collection ] arg collection to use (some commands)   -f [ --fields ] arg     comma separated list of field names e.g. -f name,age   --fieldFile arg         file with fields names - 1 per line   -q [ --query ] arg      query filter, as a JSON string   --csv                   export to csv instead of json   -o [ --out ] arg        output file; if not specified, stdout is used   --jsonArray             output to a json array rather than one object per                           line[root@localhost bin]#

  下面我們將以一個實(shí)際的例子說明,此工具的用法:
  將foo庫中的表t1導(dǎo)出成json格式:

[root@localhost bin]# ./mongoexport -d foo -c t1 -o /data/t1.json
connected to: 127.0.0.1
exported 1 records
[root@localhost bin]#

  導(dǎo)出成功后我們看一下/data/t1.json文件的樣式,是否是我們所希望的:

[root@localhost data]# more t1.json
{ "_id" : { "$oid" : "4f927e2385b7a6814a0540a0" }, "age" : 2 }
[root@localhost data]#

  通過以上說明導(dǎo)出成功,但有一個問題,要是異構(gòu)數(shù)據(jù)庫的遷移怎么辦呢?例如我們要將MongoDB的數(shù)據(jù)導(dǎo)入到MySQL該怎么辦呢?MongoDB 提供了一種csv的導(dǎo)出格式,就可以解決異構(gòu)數(shù)據(jù)庫遷移的問題了. 下面將foo庫的t2表的age和name列導(dǎo)出, 具體如下:

[root@localhost bin]# ./mongoexport -d foo -c t2 --csv -f age,name -o /data/t2.csv
connected to: 127.0.0.1
exported 1 records
[root@localhost bin]#

  查看/data/t2.csv的導(dǎo)出結(jié)果:

[root@localhost data]# more t2.csv
age,name
1,"wwl"
[root@localhost data]#

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI