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ù)項(xiàng),也可以根據(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 --help options:
--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)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。
網(wǎng)頁標(biāo)題:DBA應(yīng)用技巧中怎樣利用MySQL技能學(xué)習(xí)MongoDB-創(chuàng)新互聯(lián)
URL鏈接:http://aaarwkj.com/article22/dohecc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、外貿(mào)建站、搜索引擎優(yōu)化、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容