mapreduce - Couchbase map-reduce query to fetch list of tags -
how can count unique languages documents set this?
{ "type": "post", "lang": "en", "title": "one", } { "type": "post", "lang": "en", "title": "two", } { "type": "post", "lang": "en", "title": "three", } { "type": "post", "lang": "martian", "title": "four", } map this
function map(doc, meta) { if (meta.type !== "json") { return; } var type = doc["type"]; if (!type || type !== "post") { return; } var lang = doc["lang"]; if (!lang) { return; } emit(lang, null); } i utilize group_level 1 , grouping set true. built-in function _count returns number of documents in each language (value 3 en , 1 martian). how can reapply cut down reduced values? or should done on client?
i write map logic this:
function (doc, meta) { if(meta.type == "json") { if(doc.type && doc.type == "post") { if(doc.lang) { emit(doc.lang); } } } } i think looks clearer , easier understand @ glance. maintain count cut down rather writing new cut down function usage , said filtering in application layer.
mapreduce couchbase
No comments:
Post a Comment