博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongodb mongoexprt 导出数据 json csv格式
阅读量:4073 次
发布时间:2019-05-25

本文共 2307 字,大约阅读时间需要 7 分钟。

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)

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 - 1 per

                                                  line

      --type=<type>                               the output format, either

                                                  json or csv (defaults to

                                                  '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

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)

      --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}'

例子:

mongoexport -h 127.0.0.1:27017 -u hello -p world -d mydb -c audits -q '{actionCode:"701"}' --sort '{createDate:1}' --type=csv -f actionCode,actionName,user,createDate,createDateStr,domain -o login.csv

说明:

-h 数据地址:端口

-u 数据库用户名称

-p 数据库用户密码

-c 数据库集合名称(表名称)

-q查询条件

--sort 对查询结果按照某个字段进行排序

--type=csv 指定查询结果输出格式,csv或者json

-f 指定查询结果要输出的字段

-o 输出文件名称

转载地址:http://wxrji.baihongyu.com/

你可能感兴趣的文章
IE下诡异的注释报错——条件编译
查看>>
[转]JavaScript最全的10种跨域共享的方法
查看>>
select元素的onchange事件触发在IE,firefox,chrome的不同
查看>>
[转]最受欢迎的10个 Linux 单行命令
查看>>
[转]Web开发人员速查卡
查看>>
PHP中的is_callable函数
查看>>
Yii分析2:组件的事件机制
查看>>
[转发]I/O模型-读书笔记
查看>>
[转]关于Apache的内容协商
查看>>
[转]Managing JavaScript Objects
查看>>
[转]麻省理工免费课程)计算机科学和编程导论
查看>>
[转]打印质数的各种算法
查看>>
[转]javascript with延伸的作用域是只读的吗?
查看>>
phpDocumentor学习记录
查看>>
php的autoload与global
查看>>
IE不支持option的display:none属性
查看>>
PHP写二进制BOM头
查看>>
JQuery1.4与1.3一个很小的不同之处:关于<input type="checkbox"……
查看>>
关于JQuery UI:dialog的isOpen API使用
查看>>
[分享]mysql内置用于字符串型ip地址和整数型ip地址转换函数
查看>>