In Couchbase I have list of documment in format:
{
"article_id": "107485",
"domain": "thethao.langthuma.mr",
"category_alias": "langthuma-anh-the-thao",
"ip": "113.170.188.166",
"process_time": "635411909410581019",
"created_at": "635411845276059707"
}
I create a view:
Map
function (doc, meta) {
emit([doc.article_id,doc.domain],meta.id);
}
Reduce: (use built-in)
_sum
When I need a query like SQL:
Select article_id, domain, Count(*) from table group by article_id, domain
But i run and get error
{error,<<"Builtin _sum function requires map values to be numbers or lists of numbers">>}
Please show me where i did wrong? And solution for this?
And I want to do it with C#, any suggestion, thanks?
Your meta.id
field in your example is most likely not a number (if your document key is non-numeric) and hence cannot be used by the _sum
function. From the documentation:
_sum : will add up all values emitted to an index. For instance, for the values 3, 4, and 5 in a result set the result of the reduce function will be 12.
Assuming you just want the count of map results, not the sum of them then you should look at using the _count
built-in function instead of _sum
.
Edit: Originally misread the map function and assumed that article_id
was being emitted as the value.