查询输出:
"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
...
请帮忙!
答案 0 :(得分:0)
您基本上可以将结果存储到不同的(临时)集合中,然后使用该集合生成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.