mongodb之匯入collection
阿新 • • 發佈:2018-12-24
公司在使用mongodb資料庫,相對比較方便,今天需要實現使用RobotMongodb資料庫工具,進行匯入
匯入步驟:
- 登陸到你的mongodb伺服器,我們在liunx上安裝所以需要,ssh連線到該伺服器上
- 第二步:將檔案匯入伺服器指定目錄下;
第三步:進入mongo安裝的位置,執行命令:cd mongodb-linux-x86_64-amazon-3.4.4/
第四步:進入bin目錄,執行命令:cd bin
- 第五步:連線服務:執行命令:./mongo 127.0.0.1:20000,顯示連線成功,mongo版本即可
第六步:匯入備份檔案: `
./mongoimport --host=127. 0.0.1 --port=20000 --db=myMongoDB --collection=wechat --file=/mnt/wechat_contacts.dat`
會顯示成功匯入
connected to: 127.0.0.1:20000
2018-01-19T18:23:42.121+0800 imported 408 documents
- 測試是否匯入成功,執行以下命令
連線服務:./mongo 127.0.0.1:20000
顯示資料庫:show dbs
顯示collection:show collections
查詢第一行資料:
db.wechat.findOne()
以下為實際操記錄:
[ [email protected] ~]# ps -ef|grep mongo
root 14033 1 1 1月10 ? 03:57:54 ./mongod -f nosecurity/configsvr.conf
root 14196 1 2 1月10 ? 05:06:01 ./mongod -f nosecurity/hurricane.conf
root 14415 1 1 1月10 ? 03:39:55 ./mongod -f nosecurity/hurricane1.conf
root 14543 1 1 1月10 ? 03:22:38 ./mongod -f nosecurity/hurricane2.conf
root 14734 1 1 1月10 ? 03:20:30 ./mongod -f nosecurity/hurricane3.conf
root 15568 1 0 1月10 ? 01:02:32 ./mongos -f nosecurity/mongos.conf
root 26456 26431 0 18:21 pts/1 00:00:00 grep --color=auto mongo
[ [email protected] ~]# cd mongodb-linux-x86_64-amazon-3.4.4/
[[email protected] mongodb-linux-x86_64-amazon-3.4.4]# cd bin
[[email protected] bin]# ./mongo 127.0.0.1:20000
MongoDB shell version v3.4.4
connecting to: 127.0.0.1:20000
MongoDB server version: 3.4.4
Server has startup warnings:
2018-01-10T11:24:22.652+0800 I CONTROL [main]
2018-01-10T11:24:22.652+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2018-01-10T11:24:22.652+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2018-01-10T11:24:22.652+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2018-01-10T11:24:22.653+0800 I CONTROL [main]
mongos> show dbs
Orianna 0.652GB
WXTest 0.702GB
admin 0.000GB
config 0.006GB
dbmonopr 0.000GB
edsop 0.000GB
gjj 0.000GB
gjj2 0.700GB
moebd 0.001GB
myMongoDB 0.000GB
patent 38.846GB
polaris 0.000GB
pyxis 13.908GB
pyxism 1.273GB
qer 0.000GB
query 0.000GB
signal 0.436GB
spider 0.008GB
test 6.088GB
test_database 0.000GB
test_db 0.038GB
zptest 0.000GB
mongos> ^C
bye
[[email protected] bin]# ^C
[[email protected] bin]# ./mongoimport --host=127.0.0.1 --port=20000 --db=myMongoDB --collection=wechat --file=/mnt/wechat_contacts.dat
2018-01-19T18:23:41.664+0800 connected to: 127.0.0.1:20000
2018-01-19T18:23:42.121+0800 imported 408 documents
[[email protected] bin]# ./mongo 127.0.0.1:20000
MongoDB shell version v3.4.4
connecting to: 127.0.0.1:20000
MongoDB server version: 3.4.4
Server has startup warnings:
2018-01-10T11:24:22.652+0800 I CONTROL [main]
2018-01-10T11:24:22.652+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2018-01-10T11:24:22.652+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2018-01-10T11:24:22.652+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2018-01-10T11:24:22.653+0800 I CONTROL [main]
mongos> show dbs
Orianna 0.652GB
WXTest 0.702GB
admin 0.000GB
config 0.006GB
dbmonopr 0.000GB
edsop 0.000GB
gjj 0.000GB
gjj2 0.700GB
moebd 0.001GB
myMongoDB 0.000GB
patent 38.846GB
polaris 0.000GB
pyxis 13.908GB
pyxism 1.273GB
qer 0.000GB
query 0.000GB
signal 0.436GB
spider 0.008GB
test 6.088GB
test_database 0.000GB
test_db 0.038GB
zptest 0.000GB
mongos> use myMongoDB
switched to db myMongoDB
mongos> show collections
mycol
qq
qqBean
wechat
mongos> db.wechat.findOne()
{
"_id" : ObjectId("5a5f2a0e2b0ff39d22553e4b"),
"updatedAt" : ISODate("2018-01-17T10:48:46.388Z"),
"createdAt" : ISODate("2018-01-17T10:48:46.388Z"),
"ownerWechatId" : "kamihama",
"wechatId" : "caryxu",
"nickName" : "CaryXu",
"markName" : "瀵瀛,
"sex" : "1",
"country" : "CN",
"province" : "Shanghai",
"json" : "{\"m_nsNickName\":\"CaryXu\",\"m_nsRemark\":\"瀵瀛",\"m_uiImgKeyAtLastGet\":0,\"m_uiChatRoomStatus\":0,\"m_nsDescriptionPY\":\"\",\"m_nsWeiboNickName\":\"\",\"m_uiChatState\":0,\"m_nsEncodeUserName\":\"v1_5[email protected]stranger\",\"m_nsExternalInfo\":\"\",\"m_pcWCBGImgID\":\"http://mmsns.qpic.cn/mmsns/kqodNCVWpEvPqNgQia0eYlzBdwXq97lib3TcNxT9ibmIAPIEVcyiaV9UcuCMvGMIJiapOBZItUu2hAbg/0\",\"m_nsCertificationInfo\":\"\",\"m_nsHDImgStatus\":\"IMG_UPDATE\",\"m_nsHeadImgUrl\":\"http://wx.qlogo.cn/mmhead/ver_1/wiaervvqPXDypanDibDz4t4Qic7E4SSPdKTEJXM6Dj1vCBxrqibAia4XvGPV3drmm6kA4cnC5GsWPE4V6M42Fibv1t3zY6GKG7bbY63rKibbppaJF8/132\",\"m_uiChatRoomVersion\":0,\"m_uiQQUin\":0,\"m_nsHeadHDMd5\":\"\",\"m_nsCity\":\"\",\"m_nsChatRoomMemList\":\"\",\"m_nsUsrName\":\"caryxu\",\"m_uiWeiboFlag\":0,\"m_nsCardUrl\":\"\",\"m_nsOwner\":\"\",\"m_uiWCFlag\":1,\"m_nsHeadHDImgUrl\":\"http://wx.qlogo.cn/mmhead/ver_1/wiaervvqPXDypanDibDz4t4Qic7E4SSPdKTEJXM6Dj1vCBxrqibAia4XvGPV3drmm6kA4cnC5GsWPE4V6M42Fibv1t3zY6GKG7bbY63rKibbppaJF8/0\",\"m_nsWCBGImgObjectID\":\"12188943355137233009\",\"m_nsDescription\":\"\",\"m_nsCountry\":\"CN\",\"m_nsBrandIconUrl\":\"\",\"m_uiBrandSubscriptionSettings\":0,\"__rowID\":1466,\"m_nsDraft\":\"\",\"m_nsWeiboAddress\":\"\",\"m_nsRemarkPYShort\":\"KZ\",\"m_nsSignature\":\"寤騫磋垮勾娑彘跨
瑗欒奸┈涓灝變稿蹭哄︺\",\"m_uiDraftTime\":0,\"m_isShowRedDot\":0,\"m_nsShortPY\":\"\",\"m_uiSex\":1,\"m_uiUpdateTime\":1516182313,\"m_uiImgKey\":0,\"m_nsAliasName\":\"\",\"m_uiType\":3,\"m_uiChatRoomMaxCount\":0,\"m_uiCertificationFlag\":0,\"m_uiConType\":0,\"m_nsFullPY\":\"CaryXu\",\"m_nsGoogleContactName\":\"\",\"m_uiExtKey\":0,\"m_uiNeedUpdate\":0,\"m_nsImgStatus\":\"\",\"m_nsBrandSubscriptConfigUrl\":\"\",\"m_nsTagList\":\"2\",\"m_nsProvince\":\"Shanghai\",\"m_nsRemarkPYFull\":\"kaizi\",\"m_uiFriendScene\":4}",
"__v" : 0
}