教学之友,学习之友。

站长教学网

当前位置: 站长教学网 > 数据库 > NOSQL教程 >

mongodb导入数据的命令mongoimport

时间:2013-03-04 16:52来源:未知 作者:ken 点击:

1、远程连接 和 本地连接  ./mongo 

根据mongo  --help 可查看mongo的常用命令;
./mongo  172.16.8.189:27017/fashy  连接远程机器27017端口的fashy库。
 

 
 
./mongo --host 172.16.8.189  --port 27017  fashy  连接远程机器27017端口的fashy库
 
 

 
 
>exit 可以退出到dos窗口。
 
2、基于MongoDB支持的javascript实现远程连接
当你已经连接到一个远程的MongoDB数据库服务器(例如,通过mongo连接到192.168.0.184),现在想要在这个会话中连接另一个远程的数据库服务器(192.168.0.197),可以执行如下命令:
 

 
上述通过MongoDB提供的JavaScript脚本,实现对另一个远程数据库服务器进行连接,操作指定数据库fashy的orderInfo集合。
启动了安全认证模式,可以在获取数据库的时候添加上认证。
3、mongodb导入数据的命令mongoimport
 

 
中的命令mongoimport -h 172.16.8.189 -d fashy -c orderInfo --type csv --file E:\mongodate\1202.csv --headerline --upsert

-d    指定把数据导入到哪一个数据库中

-c    指定把数据导入到哪一个集合中

--type    指定导入的数据类型

--file       指定从哪一个文件中导入数据

--headerline    仅适用于导入csv,tsv格式的数据,表示文件中的第一行作为数据头

--upsert  以新增或者更新的方式来导入数据


options:教学网 eduyo.com
  --help                  produce help message
  -v [ --verbose ]        be more verbose (include multiple times for more
                          verbosity e.g. -vvvvv)
  --version               print the program's version and exit
  -h [ --host ] arg       mongo host to connect to ( <set name>/s1,s2 for sets)
  --port arg              server port. Can also use --host hostname:port
  --ipv6                  enable IPv6 support (disabled by default)
  -u [ --username ] arg   username
  -p [ --password ] arg   password
  --dbpath arg            directly access mongod database files in the given
                          path, instead of connecting to a mongod  server -
                          needs to lock the data directory, so cannot be used
                          if a mongod is currently accessing the same path
  --directoryperdb        if dbpath specified, each db is in a separate
                          directory
  --journal               enable journaling
  -d [ --db ] arg         database to use
  -c [ --collection ] arg collection to use (some commands)
  -f [ --fields ] arg     comma separated list of field names e.g. -f name,age
  --fieldFile arg         file with fields names - 1 per line
  --ignoreBlanks          if given, empty fields in csv and tsv will be ignored
  --type arg              type of file to import.  default: json (json,csv,tsv)
  --file arg              file to import from; if not specified stdin is used
  --drop                  drop collection first
  --headerline            CSV,TSV only - use first line as headers
  --upsert                insert or update objects that already exist
  --upsertFields arg      comma-separated fields for the query part of the
                          upsert. You should make sure this is indexed
  --stopOnError           stop importing at first error rather than continuing
  --jsonArray             load a json array, not one item per line. Currently
                          limited to 16MB.

(责任编辑:ken)
TAG标签: mongodb nosql mongoimport
顶一下
(1)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
注册登录:不允许匿名留言,登录后留言无需输入验证码。
栏目列表
最新内容