Import collection of mongodb

The company is using mongodb database, which is relatively convenient. Today, we need to use the robot mongodb database tool to import

Import steps:

  • Log in to your mongodb server, and we will install it on liunx, so we need to ssh to the server
  • Step 2: import the file into the directory specified by the server;
  • Step 3: enter the mongo installation location and execute the command: CD mongodb-linux-x86_-amazon-3.4.4/

  • Step 4: enter the bin directory and execute the command: cd bin

  • Step 5: connect to the service: execute the command. / mongo 127.0.0.1:20000, indicating that the connection is successful, and the mongo version is OK
    Step 6: import the backup file:`
./mongoimport --host=127.0.0.1 --port=20000 --db=myMongoDB --collection=wechat   --file=/mnt/wechat_contacts.dat`   
Successful import will be displayed
connected to: 127.0.0.1:20000
2018-01-19T18:23:42.121+0800    imported 408 documents
  • To test whether the import is successful, execute the following command
Connection service:. / mongo 127.0.0.1:20000
 Display database: show dbs
 show collections: Show collection s
 Query the first row of data:
db.wechat.findOne()

The following are the actual operation records:

[root@SZB-L0059780 ~]# ps -ef|grep mongo
root     14033     1  1 1 Month 10 ?        03:57:54 ./mongod -f nosecurity/configsvr.conf
root     14196     1  2 1 Month 10 ?        05:06:01 ./mongod -f nosecurity/hurricane.conf
root     14415     1  1 1 Month 10 ?        03:39:55 ./mongod -f nosecurity/hurricane1.conf
root     14543     1  1 1 Month 10 ?        03:22:38 ./mongod -f nosecurity/hurricane2.conf
root     14734     1  1 1 Month 10 ?        03:20:30 ./mongod -f nosecurity/hurricane3.conf
root     15568     1  0 1 Month 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" : "Ying Ying,
        "sex" : "1",
        "country" : "CN",
        "province" : "Shanghai",
        "json" : "{\"m_nsNickName\":\"CaryXu\",\"m_nsRemark\":\"Ying Ying",\"m_uiImgKeyAtLastGet\":0,\"m_uiChatRoomStatus\":0,\"m_nsDescriptionPY\":\"\",\"m_nsWeiboNickName\":\"\",\"m_uiChatState\":0,\"m_nsEncodeUserName\":\"v1_50c35f87a7aeb58084ee39a2b78d5ba46ae99fcd4c6072e5274099553aeeba79@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\":\"* the battle is going on.
                                    //Yuan, I'm sorry\",\"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
}

Tags: MongoDB Database Linux shell

Posted on Tue, 05 May 2020 18:11:01 -0400 by 2DaysAway