gpt4 book ai didi

couchdb 用复杂的键减少

转载 作者:行者123 更新时间:2023-12-01 04:03:15 26 4
gpt4 key购买 nike

假设我们在 couchdb 中有几个文档,像这样

{ page: 'home', country: 'EN', timestamp: 15448 }
{ page: 'search', country: 'FR', timestamp: 15448 }
{ page: 'search', country: 'EN', timestamp: 15448 }
{ page: 'home', country: 'DE', timestamp: 15457 }

每个文档代表来自具有给定时间戳的国家/地区的综合浏览量。我想要做的是查询这些文档,对于给定的页面和时间戳范围,获取该范围内每个国家/地区的综合浏览量。

我想出来的是这个 map 功能
function (doc) {
emit([doc.page, doc.timestamp, doc.country], 1)
}

_sum作为reduce函数。

我可以使用例如查询 View 。 startkey=["home",15448]&endkey=["home", 15448, {}]但这会返回每个国家/地区每天的综合浏览量,这比我需要的信息多。 (只是特定时期内每个国家/地区的综合浏览量)。

最佳答案

只是不要放出这个国家

function (doc)
{
emit([doc.page, doc.timestamp], 1)
}

减少功能
function (keys, value)
{
return sum(value);
}

关于couchdb 用复杂的键减少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11660129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com