我在沙发上陷入了以下问题。想象以下文档结构
{{name:“ test”,timestamp:12334567,value:335}
我的任务是查询特定时间范围内所有值大于X的文档。在SQL中,这将类似于
SELECT * FROM doc,其中时间戳> = X和时间戳
Z值应该是动态的,所以我不能只在发出前进行过滤。
我已经在使用startkey和endkey,但是这篇文章How exactly is startkey and endkey working in CouchDB?帮助我了解这是错误的方法。
有人可以给我一个提示,如何解决在沙发上出现这样的问题?
提前感谢。
function(doc) {
emit(['by_timestamp', doc.timestamp], null);
emit(['by_value', doc.value], null);
}
现在使用以下参数查询视图:
?startkey=['by_timestamp', X]&endkey=['by_timestamp', Y]
?startkey=['by_value', Z]&endkey=['by_value', {}]
/dbname/_all_docs?include_docs=true
得到结果,将其放入jsoned字典中:{keys: [...]}
还有瞧。
注:作为替代,您可以考虑为每个索引使用单独的map()函数。这样,您可以提高查询速度,以降低对新/更新文档的索引编制的价格。