尝试从特定帐户列表中检索事件列表(使用帐户ID),并按日期对这些事件进行排序。
这是我当前的地图功能:
function(doc) {
if (doc.doc_type == 'event' && doc.account_id) {
emit([doc.date_start,doc.account_id],doc);
}
}
当在Futon中为所有帐户运行时,这会输出正确的数据,但是,我不清楚如何构建我的请求查询或者我是否需要修改我的map函数才能完成此操作?重要的是事件在指定的一个帐户中,事件日期按顺序排序(降序)。
答案 0 :(得分:0)
您有两种选择:
对每个帐户执行查询,并在客户端上合并结果:
function(doc) {
if (doc.doc_type === 'event' && doc.account_id) {
emit([doc.account_id, doc.date_start], 1);
}
}
使用{正确的网址编码)?include_docs=true&startkey=["ACCOUNT_ID"]&endkey=["ACCOUNT_ID", {}]
查询account_id
的每个值。合并是快速而简单的,因为结果已按日期排序。
执行单个查询,并在客户端上对结果进行排序:
function(doc) {
if (doc.doc_type === 'event' && doc.account_id) {
emit(doc.account_id, 1);
}
}
使用?include_docs=true&keys=["ACCOUNT_ID1", "ACCOUNT_ID2", ...]
进行查询。排序会更慢,因为结果按account_id
排序。
只有测试才能告诉您用例的最佳选择。