mongodb mongoexprt 导出数据 json csv格式


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 输出文件名称





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值