公司在使用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 ~