0

我有以下 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})

我正在尝试将结果导出到 CSV。mongoexport 能够进行这样的查询吗?任何帮助表示赞赏。

使用 MongoDB 版本 2.2.3

4

1 回答 1

3

Mongoexport 版本 2.2.x 可以做到这一点——查询和排序。它不支持限制 - 版本 2.6 支持该选项。

查询作为 json 文档传递给 mongoexport:

- 询问

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

您可以通过 $orderby 排序(未记录但这里有一个很好的讨论):

如何使用 mongoexport 导出排序数据?

和例子:

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

直到 2.6 版才支持限制:

- 限制

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

2.6 也有不同的排序语法:

- 种类

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

超过 32 兆字节。

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

链接:

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

于 2014-07-15T17:15:15.003 回答