今天看啥
热点:

mongodb之导入collection的步骤教程,mongodbcollection


公司在使用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\":\"https://mmsns.qpic.cn/mmsns/kqodNCVWpEvPqNgQia0eYlzBdwXq97lib3TcNxT9ibmIAPIEVcyiaV9UcuCMvGMIJiapOBZItUu2hAbg/0\",\"m_nsCertificationInfo\":\"\",\"m_nsHDImgStatus\":\"IMG_UPDATE\",\"m_nsHeadImgUrl\":\"https://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\":\"https://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
}

www.bkjia.comtruehttp://www.bkjia.com/DB2/1295781.htmlTechArticlemongodb之导入collection的步骤教程,mongodbcollection 公司在使用mongodb数据库,相对比较方便,今天需要实现使用RobotMongodb数据库工具,进行导入...

相关文章

帮客评论

视觉看点