mapreduce - creating view with couchdb that does grouping and unique counting -
hi have documents so
{ domains: "domain1.com", ip: "192.168.0.1" }
documents may have different or duplicate domains/ips
i want view give me list of
domain1 => unique ip count domain
domain2 => unique ip count domain
etc..
i know how a:
domain => ip count map/reduce:
"map": "function(doc) { emit(doc.domains, 1) }",<br/> "reduce": "_sum"
and group=true parameter
but can't figure out how to a:
domain => unique ip count style list
cheers assistance, sorry english
write view map function , no reduce function
function(doc) { if (doc.domains) emit(doc.domains, doc.ip); }
then create list function counts unique entries.
function(head, req) { var ips = new array(); while (row = getrow()) { if (ips.indexof(row) != -1) { ips.push(row.value); } } send(ips.length); }
warning: code not tested, might contain bugs.
finally call list function on map view key
set domain want. note solution won't perform if have large number of ips per domain.
Comments
Post a Comment