mongodb之导入collection的步骤教程
程序员文章站
2022-03-02 17:28:19
公司在使用mongodb,相对比较方便,今天需要实现使用robotmongodb数据库工具,进行导入
导入步骤:
登陆到你的mongodb服务器,我们在liunx上安装所以需要,ssh连接到该服务器...
公司在使用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()
以下为实际操记录:
[root@szb-l0059780 ~]# 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 [root@szb-l0059780 ~]# cd mongodb-linux-x86_64-amazon-3.4.4/ [root@szb-l0059780 mongodb-linux-x86_64-amazon-3.4.4]# cd bin [root@szb-l0059780 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 [root@szb-l0059780 bin]# ^c [root@szb-l0059780 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 [root@szb-l0059780 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_50c35f87a7aeb58084ee39a2b78d5ba46ae99fcd4c6072e5274099553aeeba79@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 }
推荐阅读
-
使用mongovue把sqlserver数据导入mongodb的步骤
-
MyEclipse/Eclipse结构的JavaWeb项目导入Eclipse中运行教程 步骤
-
MySQL官方示例测试数据导入的步骤教程
-
ORACLE之账户解锁及密码修改的步骤教程
-
mongodb之导入collection的步骤教程
-
解析zend studio中直接导入svn中的项目的方法步骤_PHP教程
-
利用phpExcel实现Excel数据的导入导出(全步骤详细解析)_PHP教程
-
MyEclipse/Eclipse结构的JavaWeb项目导入Eclipse中运行教程 步骤
-
ORACLE之账户解锁及密码修改的步骤教程
-
MySQL官方示例测试数据导入的步骤教程