- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
用户可以在一个线程中发布多个评论,我尝试获取用户对其发表评论的线程(不同)列表,例如:-
// comment table (relation table)
id, thread_id, user_id
select comment.thread_id, count(*)
from user
inner join comment on user.id=comment.user_id
where user.id = ?
group by comment.thread_id;
这在 MySQL 中非常简单。
但要转换为 couchdb :-
// map
function(doc)
{
emit(doc.user_id, doc.thread_id);
}
// reduce
function (key, thread_id)
{
return thread_id;
}
如果我使用上面的 map 功能,我会遇到如下错误:-
"error": "reduce_overflow_error","reason": "Reduce output must shrink more rapidly: Current output: ...
I think I have applied the reduce function in wrong manner.
If using another way, like :-
// map
function (doc)
{
emit([doc.user_id, doc.thread_id], 1);
}
// reduce
function(keys, values)
{
return sum(values);
}
group=true
结果与 mysql group-by 的结果完全相同。
但是,我无法获取用户的所有线程列表(假设我在查询期间只有 user_id)
第三种方式,我可以放弃使用 MapReduce,直接应用:-
emit(doc.user_id, doc.thread_id);
并执行 PHP 数组,例如
foreach ( ... )
{
$threads[$thread_id] = TRUE;
}
array_keys($threads);
但是,这相当臃肿且效率较低。
第二种方法看起来更准确:-
key=[user_id, *] <-- it does not work, believe only work on exact match
key=[user_id, thread_id] <-- return one row
有没有办法在不知道 thread_id 的情况下获取所有结果?
(ps:我是 couchdb 的新手,我可能以不好的方式描述了该场景)
我通过@jasonsmith获得的一些引用资料:- http://guide.couchdb.org/draft/cookbook.html
As a rule of thumb, the reduce function should reduce to a single scalar value. That is, an integer; a string; or a small, fixed-size list or object that includes an aggregated value (or values) from the values argument. It should never just return values or similar. CouchDB will give you a warning if you try to use reduce “the wrong way”:
最佳答案
请密切关注本文档的内容:- http://wiki.apache.org/couchdb/View_Snippets#Generating_a_list_of_unique_values
// map
function(doc)
{
emit([doc.user_id, doc.thread_id], null);
}
// reduce
function (keys, values)
{
return null;
}
查询:-
?startkey=["$uid"]&endkey=["$uid",{}]&group=true
现在结果是准确的,
所以问题在于reduce函数以及查询的构造方式。
关于couchdb - 减少产出必须收缩得更快,这个错误是关于什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8324248/
我是一名优秀的程序员,十分优秀!