简体   繁体   English

将MongoDB查询转换为mongoexport

[英]Convert MongoDB query to mongoexport

I have the following Mongo query 我有以下Mongo查询

db.CustUser.find(
{"transactionData": {"$elemMatch": {"createdAt": {"$lte": ISODate("2013-07-15T00:00:00Z")}}}, "emailsSubscribed": true},
{"fname": 1, "email": 1, "_id": 0}).limit(150000).sort({"_id": -1})

I'm trying to export the results to CSV. 我正在尝试将结果导出到CSV。 Is mongoexport capable of such a query? mongoexport是否可以进行这样的查询? Any help is appreciated. 任何帮助表示赞赏。

Using MongoDB version 2.2.3 使用MongoDB 2.2.3版

Mongoexport version 2.2.x can do some of this - the query and the sort. Mongoexport版本2.2.x可以做到这一点-查询和排序。 It does not support limit - that option is supported in version 2.6. 它不支持限制-版本2.6中支持该选项。

The query is passed as a json document to mongoexport: 该查询作为json文档传递给mongoexport:

--query -查询

 Provides a JSON document as a query that optionally limits the documents returned in the export. 

You can sort via a $orderby (undocumented but here's a good discussion on it): 您可以通过$ orderby进行排序(未记录,但这是一个很好的讨论):

How to export sorted data using mongoexport? 如何使用mongoexport导出排序的数据?

and example: 和示例:

--query '{ $query: {}, $orderby: {count: -1} }'

Limit is not supported until version 2.6: 在2.6版之前不支持限制:

--limit - 限制

 Specifies a maximum number of documents to include in the export. See limit() for information about the underlying operation. 

2.6 also has different syntax for sort: 2.6的排序语法也不同:

--sort - 分类

 Specifies an ordering for exported results. If an index does not exist that can support the sort operation, the results must be less 

than 32 megabytes. 超过32兆字节。

 Use --sort conjunction with --skip and --limit to limit number of exported documents. 

Links: 链接:

http://docs.mongodb.org/manual/reference/program/mongoexport/ http://docs.mongodb.org/v2.2/reference/mongoexport/ http://docs.mongodb.org/manual/reference/program/mongoexport/ http://docs.mongodb.org/v2.2/reference/mongoexport/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM