【发布时间】:2015-03-31 21:38:55
【问题描述】:
我正在尝试使用诸如 _count 之类的 reduce 在 Couchbase 中编写视图,这将给我一个地址的产品计数。
我在数据库中有一些文件格式如下;
文档 1
{
id: 1,
address: {
street: 'W Churchill St'
city: 'Chicago',
state: 'IL',
},
product: 'Cable'
}
文档 2
{
id: 2,
address: {
street: 'W Churchill St'
city: 'Chicago',
state: 'IL',
},
product: 'Cable'
}
文档 3
{
id: 3,
address: {
street: 'W Churchill St'
city: 'Chicago',
state: 'IL',
},
product: 'Satellite'
}
文件 4
{
id: 4,
address: {
street: 'E Foster Rd'
city: 'New York',
state: 'NY',
},
product: 'Free To Air'
}
我已经有一个视图,它可以在一个使用复合键的地址为我提供所有产品,例如:
emit([doc.address.street, doc.address.city, doc.address.state], null)
现在这将我引向实际问题,我希望能够获得一个或多个地址的产品计数。
我希望能够查看“键”数组
['W Churchill St','Chicago','IL']
['E Foster Rd','New York','NY']
哪些产品和数量。所以我希望看到我的结果。
'Cable' : 2,
'Satellite': 1,
'Free To Air': 1
但是,如果我只指定了这个“键”,
['W Churchill St','Chicago','IL']
我希望看到
'Cable' : 2,
'Satellite': 1
如何编写我的视图来适应这种情况?
【问题讨论】:
标签: mapreduce couchbase reduce