设为首页 加入收藏

TOP

mongodb之导入collection的步骤教程(一)
2018-01-22 17:25:05 】 浏览:372
Tags:mongodb 导入 collection 步骤 教程

公司在使用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
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇myeclipse连接Oracle数据库详细教.. 下一篇DB2中获取用户表信息详情的方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目