mapreduce - Couchbase View _count Reduce For Given Keys -


i trying write view in couchbase using reduce such _count give me count of products @ address.

i have documents in database in following format;

document 1

{     id: 1,     address: {         street: 'w churchill st'         city: 'chicago',         state: 'il',     },     product: 'cable' } 

document 2

{     id: 2,     address: {         street: 'w churchill st'         city: 'chicago',         state: 'il',     },     product: 'cable' } 

document 3

{     id: 3,     address: {         street: 'w churchill st'         city: 'chicago',         state: 'il',     },     product: 'satellite' } 

document 4

{     id: 4,     address: {         street: 'e foster rd'         city: 'new york',         state: 'ny',     },     product: 'free air' } 

i have view gives me products @ address uses composite key such as;

emit([doc.address.street, doc.address.city, doc.address.state], null) 

now leads me on actual problem, want able count of products @ address or addresses.

i want able see array of "keys"

['w churchill st','chicago','il'] ['e foster rd','new york','ny'] 

which products , count of them. expect see in results.

'cable' : 2, 'satellite': 1, 'free air': 1 

however if specified "key",

['w churchill st','chicago','il'] 

i expect see

'cable' : 2, 'satellite': 1 

how write view accommodate this?

the solution append product key so;

emit([doc.address.street, doc.address.city, doc.address.state, doc.product], null) 

then using;

?start_key=[street,city,state]&end_key=[street,city,state,{}]&group_level=4 

result:

{"rows":[     {"key":['w churchill st','chicago','il','cable'], "value":2},     {"key":['w churchill st','chicago','il','satellite'], "value":1} ]} 

i need repeat query each of addresses , sum results.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -