欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

mongoexport和mongoimpo的使用方法

環(huán)境:MongoDB3.6.16二進(jìn)制安裝

甘谷網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,甘谷網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為甘谷上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的甘谷做網(wǎng)站的公司定做!

一、mongoexport 參數(shù)和語法介紹:

Mongodb中的mongoexport工具可以把一個collection導(dǎo)出成JSON格式或CSV格式的文件。可以通過參數(shù)指定導(dǎo)出的數(shù)據(jù)項,也可以根據(jù)指定的條件導(dǎo)出數(shù)據(jù)。

mongoexport -h IP --port 端口 -u 用戶名 -p 密碼 -d 數(shù)據(jù)庫 -c 表名 -f 字段 -q 條件導(dǎo)出 --csv -o 文件名

-h 指明數(shù)據(jù)庫宿主機的IP
-u 指明數(shù)據(jù)庫的用戶名
-p 指明數(shù)據(jù)庫的密碼
-d 指明數(shù)據(jù)庫的名字
-c 指明collection的名字
-f 指明要導(dǎo)出那些列,以逗號分割,-f uid,name,age導(dǎo)出uid,name,age這三個字段
-o 指明到要導(dǎo)出的文件名
-q 指明導(dǎo)出數(shù)據(jù)的過濾條件,-q '{ "uid" : "100" }' 導(dǎo)出uid為100的數(shù)據(jù)
--type 指定文件類型
--authenticationDatabase 驗證數(shù)據(jù)的名稱

導(dǎo)出整張表數(shù)據(jù):

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu  -o ./1.dat
2020-01-05T11:54:48.956+0800    connected to: 127.0.0.1:6068
2020-01-05T11:54:48.956+0800    exported 3 records

[root@localhost ~]# cat 1.dat 
{"_id":{"$oid":"5e0f162d1083b09e85237cb4"},"name":"小花","年級":"二年級","性別":"男","愛好":"學(xué)習(xí)"}
{"_id":{"$oid":"5e0f161d1083b09e85237cb3"},"name":"小花","年級":"二年級","性別":"男","愛好":"學(xué)習(xí)"}
{"_id":{"$oid":"5e0f16191083b09e85237cb2"},"name":"小花","年級":"二年級","性別":"男","愛好":"學(xué)習(xí)"}

導(dǎo)出表指定字段的數(shù)據(jù):

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu -f name,'年級','性別' -o ./2.dat
2020-01-05T11:55:41.187+0800    connected to: 127.0.0.1:6068
2020-01-05T11:55:41.187+0800    exported 3 records
[root@localhost ~]# cat 2.dat 
{"_id":{"$oid":"5e0f162d1083b09e85237cb4"},"name":"小花","年級":"二年級","性別":"男"}
{"_id":{"$oid":"5e0f161d1083b09e85237cb3"},"name":"小花","年級":"二年級","性別":"男"}
{"_id":{"$oid":"5e0f16191083b09e85237cb2"},"name":"小花","年級":"二年級","性別":"男"}

導(dǎo)出表指定字段的csv格式數(shù)據(jù):

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu --type csv -f name,'年級' -o ./3.csv
[root@localhost ~]# cat 3.csv 
name,年級
小花,二年級
小花,二年級
小花,二年級
[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu --csv -f name,'年級' -o ./1.csv
2020-01-05T11:58:56.598+0800    csv flag is deprecated; please use --type=csv instead
2020-01-05T11:58:56.599+0800    connected to: 127.0.0.1:6068
2020-01-05T11:58:56.600+0800    exported 3 records
[root@localhost ~]# cat 1.csv 
name,年級
小花,二年級
小花,二年級
小花,二年級

導(dǎo)出json格式文件,默認(rèn)導(dǎo)出的就是json格式的數(shù)據(jù)文件:

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu --type json -f name,'年級' -o ./2.json
2020-01-05T12:01:28.951+0800    connected to: 127.0.0.1:6068
2020-01-05T12:01:28.951+0800    exported 3 records
[root@localhost ~]# cat 2.json 
{"_id":{"$oid":"5e0f162d1083b09e85237cb4"},"name":"小花","年級":"二年級"}
{"_id":{"$oid":"5e0f161d1083b09e85237cb3"},"name":"小花","年級":"二年級"}
{"_id":{"$oid":"5e0f16191083b09e85237cb2"},"name":"小花","年級":"二年級"}

根據(jù)條件導(dǎo)出數(shù)據(jù):
愛好打球的記錄數(shù):

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c chenji -q '{"愛好":"打球"}' -o ./daqiu.json
2020-01-05T12:10:21.788+0800    connected to: 127.0.0.1:6068
2020-01-05T12:10:21.788+0800    exported 2 records
[root@localhost ~]# cat daqiu.json 
{"_id":{"$oid":"5e1160a3ef45ab936b74982a"},"name":"李四","年級":"一年級","性別":"女","愛好":"打球"}
{"_id":{"$oid":"5e116102ef45ab936b74982d"},"name":"趙武","年級":"五年級","性別":"男","愛好":"打球"}

二、mongoimport語法和參數(shù)介紹:

Mongodb中的mongoimport工具可以把一個特定格式文件中的內(nèi)容導(dǎo)入到指定的collection中。該工具可以導(dǎo)入JSON格式數(shù)據(jù),也可以導(dǎo)入CSV格式數(shù)據(jù)。

參數(shù)介紹:
-h 指明數(shù)據(jù)庫宿主機的IP
-u 指明數(shù)據(jù)庫的用戶名
-p 指明數(shù)據(jù)庫的密碼
-d 指明數(shù)據(jù)庫的名字
-c 指明collection的名字
-f 指明要導(dǎo)出那些列
-o 指明到要導(dǎo)出的文件名
-q 指明導(dǎo)出數(shù)據(jù)的過濾條件
--drop 插入之前先刪除原有的
--headerline 指明第一行是列名,不需要導(dǎo)入。
-j 同時運行的插入操作數(shù)(默認(rèn)為1),并行
--authenticationDatabase 驗證數(shù)據(jù)的名稱

導(dǎo)出數(shù)據(jù),然后在恢復(fù)到表里面:
導(dǎo)出數(shù)據(jù):

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c fenshu   -o ./111.bat
2020-01-05T12:46:21.264+0800    connected to: 127.0.0.1:6068
2020-01-05T12:46:21.265+0800    exported 8 records

恢復(fù)到表里面:

[root@localhost ~]# mongoimport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c fenshu --drop ./111.bat
2020-01-05T12:50:07.154+0800    connected to: 127.0.0.1:6068
2020-01-05T12:50:07.154+0800    dropping: dbtest002.fenshu
2020-01-05T12:50:07.181+0800    imported 7 documents

部分字段的表數(shù)據(jù)導(dǎo)入:
指定字段導(dǎo)出:

[root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c fenshu --type json -f name,'年級' -o ./222.bat
2020-01-05T12:57:16.030+0800    connected to: 127.0.0.1:6068
2020-01-05T12:57:16.030+0800    exported 7 records

指定字段導(dǎo)入表時避免主鍵沖突,因而加參數(shù)--drop

[root@localhost ~]# mongoimport   -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c fenshu  --upsertFields name,'年級' --drop ./222.bat 
2020-01-05T12:58:22.422+0800    connected to: 127.0.0.1:6068
2020-01-05T12:58:22.428+0800    imported 7 documents

當(dāng)前名稱:mongoexport和mongoimpo的使用方法
本文URL:http://www.chinadenli.net/article20/iggpjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站微信小程序App設(shè)計云服務(wù)器網(wǎng)站策劃網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)