我的Couch数据库中有以下数据结构。我需要得到每天不同sessions_id
的计数。记录也必须通过app_version
进行筛选。
我当前的MapReduce看起来像这个
"dau": {
"map": "function(doc) {
date = doc.session.timestamp.split("T")[0];
emit([date, doc.app_version, doc.session.session_id], 1);
}",
"reduce": "_count"
}
但这给了我以下的输出
["2014-08-20", 2, "kOnNIhCNQ31LlkpEPQ7XnN1D"] 1 ["2014-08-20", 2, "TOnNIhCNQ31LlkpEPQ7XnN1D"] 2 ["2014-08-21", 2, "TOnNIhCNQ31LlkpEPQ7XnN1D"] 2
我需要将其打印为-因为这是每天的唯一session_id
的数量
["2014-08-20", 2] 2 ["2014-08-21", 2] 1
有什么想法吗?
任何帮助都将不胜感激。
[
{
"app_version": 2,
"platform": "android",
"session": {
"timestamp": "2014-08-20T00:00:00.000Z",
"session_id": "TOnNIhCNQ31LlkpEPQ7XnN1D",
"ip": "202.150.213.66",
"location": "1.30324,103.5498"
}
},
{
"app_version": 2,
"platform": "android",
"session": {
"timestamp": "2014-08-21T00:00:00.000Z",
"session_id": "TOnNIhCNQ31LlkpEPQ7XnN1D",
"ip": "202.150.213.66",
"location": "1.30324,103.5498"
}
}
{
"app_version": 2,
"platform": "ios",
"session": {
"timestamp": "2014-08-21T00:00:00.000Z",
"session_id": "TOnNIhCNQ31LlkpEPQ7XnN1D",
"ip": "202.150.213.66",
"location": "1.30324,103.5498"
}
},
{
"app_version": 1,
"platform": "ios",
"session": {
"timestamp": "2014-08-21T00:00:00.000Z",
"session_id": "TOnNIhCNQ31LlkpEPQ7XnN1D",
"ip": "202.150.213.66",
"location": "1.30324,103.5498"
}
}
]
将app_version放在视图的第一位:
emit([doc.app_version, date, doc.session.session_id], 1);
然后使用group_level=2 进行查询