在MongoDB mapreduce中,如何展平values对象? [英] In MongoDB mapreduce, how can I flatten the values object?
问题描述
我正在尝试使用MongoDB分析Apache日志文件.我已经从Apache访问日志中创建了一个receipts
集合.以下是我的模型的简要摘要:
I'm trying to use MongoDB to analyse Apache log files. I've created a receipts
collection from the Apache access logs. Here's an abridged summary of what my models look like:
db.receipts.findOne()
{
"_id" : ObjectId("4e57908c7a044a30dc03a888"),
"path" : "/videos/1/show_invisibles.m4v",
"issued_at" : ISODate("2011-04-08T00:00:00Z"),
"status" : "200"
}
我编写了 MapReduce函数,该函数按issued_at
日期字段将所有数据分组.它总结了请求的总数,并提供了每个唯一路径的请求数的细分.这是输出结果的示例:
I've written a MapReduce function that groups all data by the issued_at
date field. It summarizes the total number of requests, and provides a breakdown of the number of requests for each unique path. Here's an example of what the output looks like:
db.daily_hits_by_path.findOne()
{
"_id" : ISODate("2011-04-08T00:00:00Z"),
"value" : {
"count" : 6,
"paths" : {
"/videos/1/show_invisibles.m4v" : {
"count" : 2
},
"/videos/1/show_invisibles.ogv" : {
"count" : 3
},
"/videos/6/buffers_listed_and_hidden.ogv" : {
"count" : 1
}
}
}
}
如何使输出看起来像这样:
How can I make the output look like this instead:
{
"_id" : ISODate("2011-04-08T00:00:00Z"),
"count" : 6,
"paths" : {
"/videos/1/show_invisibles.m4v" : {
"count" : 2
},
"/videos/1/show_invisibles.ogv" : {
"count" : 3
},
"/videos/6/buffers_listed_and_hidden.ogv" : {
"count" : 1
}
}
}
推荐答案
It's not currently possible, but I would suggest voting for this case: https://jira.mongodb.org/browse/SERVER-2517.
这篇关于在MongoDB mapreduce中,如何展平values对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!