MongoDB导入(mongoimport)-导出(mongoexport)工具使用
1、导出工具-mongoexport
Mongodb中的mongoexport工具可以把一个collection导出为JSON格式或者CSV格式文件。
(1)、导出为JSON文件
/opt/mongodb/bin/mongoexport -h 127.0.0.1 -u user -p password --port 27017 -d dev_test_db -c dev_test_history_location -q '{"handle" : "30487"}' -o history_location_30487.dat
(2)、导出为CSV文件
/opt/mongodb/bin/mongoexport -u user -p password --port 27017 -d dev_test_db -c dev_test_location --csv -q '{"handle" : "30439"}' -o dev_test_location_30439.csv --field type,handle,create_time
具体参数说明如下:
Options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times
for more verbosity e.g. -vvvvv)
--quiet silence all non error diagnostic
messages
--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
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR)
authentication mechanism
--gssapiServiceName arg (=mongodb) Service name to use when authenticating
using GSSAPI/Kerberos
--gssapiHostName arg Remote host name to use for purpose of
GSSAPI/Kerberos authentication
--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 each db is in a separate directory
(relevant only if dbpath specified)
--journal enable journaling (relevant only if
dbpath specified)
-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 field names - 1 per line
-q [ --query ] arg query filter, as a JSON string, e.g.,
'{x:{$gt:1}}'
--csv export to csv instead of json
-o [ --out ] arg output file; if not specified, stdout
is used
--jsonArray output to a json array rather than one
object per line
-k [ --slaveOk ] arg (=1) use secondaries for export if
available, default true
--forceTableScan force a table scan (do not use
$snapshot)
--skip arg (=0) documents to skip, default 0
--limit arg (=0) limit the numbers of documents
returned, default all
--sort arg sort order, as a JSON string, e.g.,
'{x:1}'
2、导入工具-mongoimport
(1)、JSON格式文件导入
/opt/mongodb/bin/mongoimport -h 127.0.0.1 -u user -p password --port 27017 -d dev_test_db -c dev_test_history_location history_location_30487.dat
(2)、CSV格式文件导入
/opt/mongodb/bin/mongoimport -h 127.0.0.1 -u user -p password --port 27017 -d dev_test_db -c dev_test_history_location --type csv --headline --file history_location_30487.csv
参数说明:
-type: 指明要导入的文件格式
-headerline: 指明第一行是列名,不需要导入
-file: 指明要导入的文件
Options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times
for more verbosity e.g. -vvvvv)
--quiet silence all non error diagnostic
messages
--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
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR)
authentication mechanism
--gssapiServiceName arg (=mongodb) Service name to use when authenticating
using GSSAPI/Kerberos
--gssapiHostName arg Remote host name to use for purpose of
GSSAPI/Kerberos authentication
--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 each db is in a separate directory
(relevant only if dbpath specified)
--journal enable journaling (relevant only if
dbpath specified)
-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 field 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 first line in input file is a header
(CSV and TSV only)
--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.
MongoDB导入(mongoimport)-导出(mongoexport)工具使用的更多相关文章
- Oracle Imp and Exp (导入和导出) 数据 工具使用
Oracle 提供两个工具imp.exe 和exp.exe分别用于导入和导出数据.这两个工具位于Oracle_home/bin目录下. 导入数据exp 1 将数据库ATSTestDB完全导出,用户名s ...
- mongodb导入,导出实例
MongoDB中文手册|官方文档中文版 英文版:https://docs.mongodb.com/manual/ 1.mongoexport 导出文件 打开命令行,进入我们所安装的mongodb路径下 ...
- 【MongoDB】mongoimport and mongoexport of data (一)
In the software development, we usually are faced with a common question of exporting or importing d ...
- TFS 测试用例导入、导出工具
TFS的测试管理提供了测试规划.创建.运行以及进度跟踪等功能.测试人员通过浏览器就几乎可以完成手个测试的全部过程. 用过TFS测试用例的朋友们,很多人应该都知道,在TFS的Portal中以及相应的数据 ...
- mongodb数据导入导出mongoexport/mongoimport
数据导出 mongoexport 假设库里有一张user表,里面有2条记录,我们要将它导出 > use my_mongodb switched to db my_mongodb > db. ...
- Mongodb的备份,恢复,导入与导出(cmd命令行实现)
要用MongoDB,自然就要用到数据导入导出,就自己学习了一下. 在Mongo学习(二)中就讲到了在bin目录下有一些工具,本篇就是使用这些工具进行数据的导入导出及备份恢复. 注意:以下命令均在cmd ...
- MongoDB导入导出以及数据库备份
-------------------MongoDB数据导入与导出------------------- 1.导出工具:mongoexport 1.概念: mongoDB中的m ...
- MongoDB导入导出以及数据库备份以及.dat数据
1.导出工具:mongoexport 1.概念: mongoDB中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件.可以通过参数指 ...
- Mongodb 备份 数据导出导入
MongoDB 客户端工具 mongochef 可以进行一系类操作 MongoDB 非客户端操作 : mongod 备份导出 mongoexport -h IP --port 端口 -u 用户名 -p ...
随机推荐
- html_博客博主
csdn: 工匠若水 http://blog.csdn.net/yanbober yunama: IT蓝豹:http://www.itlanbao.com/: http://ask.dcloud.ne ...
- Framework4.5语法糖 异步Task
1.线程安全 在使用TaskRun的时候需要注意线程安全的问题. 线程安全通常是由全局变量及静态变量引起的,如果是值类型就不存在这样的隐患,如果是引用类型用不好就会导致线程不安全! 2.Task.Ta ...
- 磁盘的读写-想起了SGA PGA DBWR LGWR...
衡量性能的几个指标的计算中我们可以看到一个15k转速的磁盘在随机读写访问的情况下IOPS竟然只有140左右,但在实际应用中我们却能看到很多标有5000IOPS甚至更高的存储系统,有这么大IOPS的存储 ...
- day10-redis操作
Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorte ...
- sqlserver获取数据库表结构
SqlServer获取所有数据库,表,表结构 --获取所有数据库 SELECT * FROM Master..SysDatabases ORDER BY Name --获取test数据库下所有表 us ...
- Django 开发投票系统
主要参考官方文档 Windows 10 Python 23.5 Django 1.9 1.创建项目(mysite)与应用(polls) D:\python>django-admin.py st ...
- Android学习起步 - Button按钮及事件处理
按钮和文本框算是比较简单的控件了,以下主要讲按钮的事件响应,三种写法(匿名内部类响应事件.外部类响应事件.本类直接响应事件) 点击按钮后文本框中会显示 ”按钮被单击了”,先看效果: 以下是这个界面的布 ...
- 慕课网-Java入门第一季-6-7 使用 Arrays 类操作 Java 中的数组
来源:http://www.imooc.com/code/1556 Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现 ...
- Java多线程Thread
转自:http://www.cnblogs.com/lwbqqyumidi/p/3804883.html Java总结篇系列:Java多线程(一) 多线程作为Java中很重要的一个知识点,在此还是 ...
- c#winform程序,修改MessageBox提示框中按钮的文本
用winform的MessageBox是实现不了的,这里我用的是DevExpress控件的XtraMessageBoxForm 例如如果想在一个提示框里修改"是","否& ...