mongoDB 数据导入

来源:互联网 发布:网络分离器哪个牌子好 编辑:程序博客网 时间:2024/06/05 00:57

       mongoDB 数据导入

步骤:


1.准备数据:如果手上没有json数据格式的文档,可以把https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/dataset.json上的数据下载下来。

2.导入:mongoDB提供了mongoimport 工具来导入外部数据,在mongoDB安装目录里的bin目录下可以看到它。

下面的数据导入操作是把我本地的primer-dataset.json文件,导入到test数据库下的restaurants集合里。


[mongo@localhost bin]$  cd /opt/software/mongodb-linux-x86_64-3.0.6/bin

[mongo@localhost bin]$ ./mongoimport --db test --collection restaurants --drop  --file /opt/testData/primer-dataset.json



命令解说:

--db test :导入到test的目标数据库,如果test数据库不存在,mongoDB会新建一个。

--collection restaurants  --drop: 指定数据导入的目标集合,如果restaurants集合不存在,mongoDB会新建一个,如果已经存在,后面的--drop命令会删除它。

--file:指定数据源文件。

0 0
原创粉丝点击