在mongodb的bin目录下, 有一个mongoexport, 可用于数据的导出

[wenbronk@localhost bin]$ ./mongoexport --help
Usage:
mongoexport <options> Export data from MongoDB in CSV or JSON format. See http://docs.mongodb.org/manual/reference/program/mongoexport/ for more information. general options:
--help print usage
--version print the tool version and exit verbosity options:
-v, --verbose=<level> more detailed log output (include multiple times for more verbosity, e.g.
-vvvvv, or specify a numeric value, e.g. --verbose=N)
--quiet hide all log output connection options:
-h, --host=<hostname> mongodb host to connect to (setname/host1,host2 for replica sets)
--port=<port> server port (can also use --host hostname:port) ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate
authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> the .pem file containing the certificate revocation list
--sslAllowInvalidCertificates bypass the validation for server certificates
--sslAllowInvalidHostnames bypass the validation for server name
--sslFIPSMode use FIPS mode of the installed openssl library authentication options:
-u, --username=<username> username for authentication
-p, --password=<password> password for authentication
--authenticationDatabase=<database-name> database that holds the user's credentials
--authenticationMechanism=<mechanism> authentication mechanism to use namespace options:
-d, --db=<database-name> database to use
-c, --collection=<collection-name> collection to use output options:
-f, --fields=<field>[,<field>]* comma separated list of field names (required for exporting CSV) e.g. -f
"name,age"
--fieldFile=<filename> file with field names - per line
--type=<type> the output format, either json or csv (defaults to 'json') (default: json)
-o, --out=<filename> output file; if not specified, stdout is used
--jsonArray output to a JSON array rather than one object per line
--pretty output JSON formatted to be human-readable
--noHeaderLine export CSV data without a list of field names at the first line querying options:
-q, --query=<json> query filter, as a JSON string, e.g., '{x:{$gt:1}}'
--queryFile=<filename> path to a file containing a query filter (JSON)
-k, --slaveOk allow secondary reads if available (default true) (default: false)
--readPreference=<string>|<json> specify either a preference name or a preference json object
--forceTableScan force a table scan (do not use $snapshot)
--skip=<count> number of documents to skip
--limit=<count> limit the number of documents to export
--sort=<json> sort order, as a JSON string, e.g. '{x:1}'
--assertExists if specified, export fails if the collection does not exist (default:
false)

导出文件到json中:

导出到json:
$ mongoexport.exe -d TestDB -c TestCollection -o ./test.json

导出文件到csv中

./mongoexport --csv -f _id,userId,report_point,matched_line,mode,match_point,predict_point,predict
_lines,poi_ids,is_moved,time,date_time -d mapmatch -c -- -o /opt/wenbronk_soft/--.csv

可能会出现乱码, 用记事本另存utf-8 就可以了

在使用-q 查询条件过滤数据的时候,注意两边的 ’ (单引号)

当数据量很大时候,可以使用--skip 配合 --limit,限制单个文件的数据量,方便普通用户查看

mongodb-导出数据到csv文件或json文件的更多相关文章

  1. mongodb导出数据到csv

    mongo cws export.js > out.csv export.js // Date.prototype.getIOSDate = function () { return new D ...

  2. PHP导出数据到CSV文件函数 csv_export()

    后台往往需要导出各种数据到 Excel文档中.通常我们是导出 .csv文件格式,PHP导出函数参考代码如下: /** * 导出数据到CSV文件 * * @param array $data 二维数组( ...

  3. PHP导出数据到CSV文件函数/方法

    如果不清楚什么是CSV文件,可看如下文章介绍  CSV格式的是什么文件?CSV是什么的缩写? /** * 导出数据到CSV文件 * @param array $data 数据 * @param arr ...

  4. PHP导出数据到CSV文件

    后台往往需要导出各种数据到 Excel文档中.通常我们是导出 .csv文件格式,PHP导出函数参考代码如下: /** * 导出数据到CSV文件 * * @param array $data 二维数组( ...

  5. mysql导出数据到csv文件

    在日常工作中经常会遇见导出表中的数据到csv文件的操作,这里就简单总结一下导出的操作. 下面对csv文件的描述是摘录: 据RFC4180文档设置的,该文档全称Common Format and MIM ...

  6. php导出数据到csv

    序言 php导出数据到csv是一种很常见的功能,且csv相比于excel文件有其一定的优势,首先csv对数据的行数没有限制,但是excel对数据的行数有一定的限制,因此,csv文件对于导出大量的数据来 ...

  7. C#导出数据到CSV和EXCEL文件时数字文本被转义的解决方法

    今天写C#导出datagrid数据到csv格式文件的时候,发现不管怎么尝试,凡是单元格里面全是数字的单元格,在用Excel打开的时候,都被自动转义成数据格式.数据查看极其不方便.最后google了一下 ...

  8. mongodb导出数据表命令之mongoexport

    mongoexport导出文件格式支持csv和json,不同的是csv格式必须显示的指定要导出的字段,如: mongoexport -d rbac -c rbacs -o d:/web/rbac.cs ...

  9. 【shell mysql 导出数据到csv脚本,完美解决乱码转义符等问题】-费元星

    #!/bin/bash#@author:feiyuanxing [既然笨到家,就要努力到家]#@date:2017-12-05#@E-Mail:feiyuanxing@gmail.com#@TARGE ...

随机推荐

  1. 简便方法搞定第三方SDK的Jar包在DelphiXE5中的引入

    简便方法搞定第三方SDK的Jar包在DelphiXE5中的引入 (2014-02-21 17:30:17) 转载▼ 标签: android delphi xe5 jar sdk 分类: 编程杂集 折腾 ...

  2. Hyper-V启动虚拟机,消耗C盘大量磁盘空间

    问题描述 经常使用Hyper-V虚拟机的朋友,可能会碰到这样的现象,当启动某些虚拟机的是否,发现C盘的空间突然减少,减少的空间与虚拟机的内存一样大少. 通过分析C盘空间的磁盘文件,发现在Hyper-V ...

  3. linux系统编程之管道(三):命令管道(FIFO)

    一,匿名管道PIPE局限性 管道的主要局限性正体现在它的特点上: 只支持单向数据流: 只能用于具有亲缘关系的进程之间: 没有名字: 管道的缓冲区是有限的(管道制存在于内存中,在管道创建时,为缓冲区分配 ...

  4. linux系统编程之进程(六):父进程查询子进程的退出,wait,waitpid

    本节目标: 僵进程 SIGCHLD wait waitpid 一,僵尸进程 当一个子进程先于父进程结束运行时,它与其父进程之间的关联还会保持到父进程也正常地结束运行,或者父进程调用了wait才告终止. ...

  5. c# 字符串去掉两端空格,并且将字符串中多个空格替换成一个空格

    字符串去掉两端空格,并且将字符串中多个空格替换成一个空格: 主要还是考察使用字符串的方法: trim(); 去掉字符串两端空格 split(); 切割 string.join(); 连接 class ...

  6. Mac 切换到行首和行末的方法

    苹果笔记本没有home键和end键 但是使用 command + 方向键左键可以回到行首, command + 方向键右键可以去到行末

  7. 记自己的第一个完整的java web项目

    我是从asp.net平台转到java平台的.基于asp.net平台开发网站的快速便捷性,工作几年来大小网站多少也写了6.7个.但是转到java后,因为是在一家大公司,而且做的功能也比较单一,局限于此, ...

  8. Kafka数据可靠性与一致性解析

    Partition Recovery机制 每个Partition会在磁盘记录一个RecoveryPoint, 记录已经flush到磁盘的最大offset.broker fail 重启时,会进行load ...

  9. Flask从入门到精通之MySQL数据库操作

    前面的章节中我们已经学习了如何建立模型和关系,接下来我们学习如何使用模型的最好方法是在Python shell 中实际操作.并将介绍最常用的数据库操作. 一.创建表 首先,我们要让Flask-SQLA ...

  10. webpack快速入门——配置文件:服务和热更新

    1.在终端安装 cnpm i webpack-dev-server --save-dev 2.配置好后执行 webpack-dev-server,这时候会报错 出现错误,只需要在pagejson里配置 ...