Mongodb import collection step tutorial, mongodbcollection
It is relatively convenient for companies to use mongodb databases. Today we need to use the RobotMongodb database tool for import.
Import steps:
Log on to your mongodb server. We need to install it on liunx. Connect to the server via ssh. Step 2: import the file to the specified directory on the server;
Step 3: Go to the mongo installation location and run the command: cd mongodb-linux-x86_64-amazon-3.4.4/
Step 4: Go to the bin directory and run the command: cd bin
Step 5: connect to the service: run the command:./mongo 127.0.0.1: 20000. The connection is successful and the mongo version is enough.
Step 6: import the backup file :'
./mongoimport --host=127.0.0.1 --port=20000 --db=myMongoDB --collection=wechat --file=/mnt/wechat_contacts.dat`
The imported data is displayed.
connected to: 127.0.0.1:200002018-01-19T18:23:42.121+0800 imported 408 documents
Run the following command to test whether the import is successful:
Connection Service:./mongo 127.0.0.1: 20000 display Database: show dbs display collection: show collections query first row data: db. wechat. findOne ()
The actual operation records are as follows:
[Root @ SZB-L0059780 ~] # Ps-ef | grep Limit root 14033 1 May January 10? 03:57:54./mongod-f nosecurity/configsvr. confroot 14196 1 2 May January 10? 05:06:01./mongod-f nosecurity/hurricane. confroot 14415 1 January 10? 03:39:55./mongod-f nosecurity/hurricane1.confroot 14543 1 January 10? 03:22:38./mongod-f nosecurity/hurricane2.confroot 14734 1 January 10? 03:20:30./mongod-f nosecurity/hurricane3.confroot 15568 1 0 January 10? 01:02:32./mongos-f nosecurity/mongos. confroot 26456 26431 0 00:00:00 pts/1 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.4connecting to: 127.0.0.1: 20000 MongoDB server version: 3.4.4Server has startup warnings: 2011-1-10t11: 24: 22.652 + 0800 I CONTROL [main] 2011-1-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 dbsOrianna 0.652 GBWXTest 0.702 GBadmin 0.000 GBconfig 0.006 GBedsop 0.000 GBgjj runtime 0.000 GBmyMongoDB 0.700 GBpatent 0.001 GBpolaris 0.000 GBpyxis 38.846 GBpyxism 0.000 GBqer 13.908 GBquery 0.000 GBsignal 0.436 GBspider 0.008 GBtest 6.088GBtest _ database 0.000GBtest _ db 0.038 GBzptest 0.000 GBmongos> ^ Cbye [root @ SZB-L0059780 bin] # ^ C [root @ SZB-L0059780 bin] #. /Export Import -- host = 127.0.0.1 -- port = 20000 -- db = myMongoDB -- collection = wechat -- file =/mnt/wechat_contacts.dat2018-01-19T18: 23: 41.664 + 0800 connected to: 127.0.0.1: 200002011-191-19t18: 23: 42.121 + 0800 imported 408 documents [root @ SZB-L0059780 bin] #. /mongo 127.0.0.1: 20000 MongoDB shell version v3.4.4connecting to: 127.0.0.1: 20000 MongoDB server version: 3.4.4Server has startup warnings: 2011-1-10t11: 24: 22.652 + 0800 I CONTROL [main] 2011-1-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 dbsOrianna 0.652 GBWXTest 0.702 GBadmin 0.000 GBconfig 0.006 GBedsop 0.000 GBgjj runtime 0.000 GBmyMongoDB 0.700 GBpatent 0.001 GBpolaris 0.000 GBpyxis 38.846 GBpyxism 0.000 GBqer 13.908 GBquery 0.000 GBsignal 0.436 GBspider 0.008 GBtest 6.088GBtest _ database 0.000GBtest _ db 0.038 GBzptest 0.000 GBmongos> use myMongoDBswitched to db myMongoDBmongos> show collectionsmycolqqqqBeanwechatmongos> db. wechat. findOne () {"_ id": ObjectId ("updated"), "updatedAt": ISODate ("2018-01-17T10: 48: 46.388Z"), "createdAt": ISODate ("2018-01-17T10: 48: 46.388Z ")," ownerWechatId ":" kamihama "," wechatId ":" caryxu "," nickName ":" CaryXu "," markName ":" zookeeper, "sex": "1", "country": "CN", "province": "Shanghai", "json": "{\" m_nsNickName \": \ "CaryXu \", \ "m_nsRemark \": \ "invalid Parameters", \ "m_uiImgKeyAtLastGet \": 0, \ "m_uiChatRoomStatus \": 0, \ "m_nsDescriptionPY \": \ "\", \ "m_nsweibo onickname \": \ "\", \ "m_uiChatState \": 0, \ "m_nsEncodeUserName \": \ "comment @ 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 \": \ "How can this problem be solved?", \ "m_uiDraftTime \": 0, \ "m_isShowRedDot \": 0, \ "m_ns1_py \": \ "\", \ "m_uiSex \": 1, \ "m_uiUpdateTime \": 1516182313, \ "m_uiImgKey \": 0, \ "m_nsAliasName \": \ "\", \ "m_uiType \": 3, \ "m_uiChatRoomMaxCount \": 0, \ "m_uicertifflaflag \": 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}