【问题标题】:Convert MongoDB query to mongoexport将 MongoDB 查询转换为 mongoexport
【发布时间】:2014-07-16 01:15:15
【问题描述】:

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

【问题讨论】:

  • 如果没有,我就继续写一个脚本。在这种情况下是否可以使用 mongoexport 或多或少好奇。

标签: mongodb mongoexport


【解决方案1】:

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 进行排序(未记录,但这里有一个很好的讨论):

How to export sorted data using 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-02-22
    • 1970-01-01
    • 2018-08-28
    • 2020-01-19
    • 2021-10-13
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 2021-02-13
    相关资源
    最近更新 更多