【问题标题】:CSV output from mongo query来自 mongo 查询的 CSV 输出
【发布时间】:2014-08-21 08:44:26
【问题描述】:

查询输出:

"result" : [
            {
                "total" : 149,
                "email" : "TEST8@GMAIL.COM"
            },
            {
                "total" : 54,
                "email" : "TEST7@GMAIL.COM"
            } ...
        ],
        "ok" : 1

查询:Aggregate Query in Mongodb returns specific field

现在我正在尝试将查询输出导出到 csv 文件。我想得到如下所示的输出文件:

total(column 1)  Email(column 2)
149              TEST8@GMAIL.COM
54               TEST7@GMAIL.COM
... 

请帮忙!

【问题讨论】:

  • 这个问题的答案可能会有所帮助。 [stackoverflow.com/questions/8971151/…
  • 我已经试过了,给我这个回复 Thu Aug 21 14:35:31.844 TypeError: Object [object Object] has no method 'hasNext'

标签: mongodb


【解决方案1】:

您基本上可以将结果存储到不同的(临时)集合中,然后使用该集合生成 csv。这可以通过在聚合管道中添加 $out 字段来完成。

这里有很好的例子和解释:http://docs.mongodb.org/manual/reference/operator/aggregation/out/

-- 来自链接

$out

Takes the documents returned by the aggregation pipeline and writes them to a specified collection. The $out operator must be the last stage in the pipeline. The $out operator lets the aggregation framework return result sets of any size.

【讨论】:

  • 您从正确的音符开始。进一步对此集合进行简单的 mongoexport 将产生所需的结果。
猜你喜欢
  • 2013-01-06
  • 1970-01-01
  • 1970-01-01
  • 2021-04-18
  • 2016-01-27
  • 1970-01-01
  • 2020-11-17
  • 2018-04-16
相关资源
最近更新 更多