我正在使用http://docs.couchdb.org/en/1.6.1/intro/tour.html示例,该示例适用于以下设置:
curl -X PUT http://127.0.0.1:5984/demo
curl -H 'Content-Type: application/json' -X POST http://127.0.0.1:5984/demo \
-d '{"item": "apple","prices": {"Fresh Mart": 1.59,
"Price Max": 5.99,
"Apples Express": 0.79}}'
curl -H 'Content-Type: application/json' -X POST http://127.0.0.1:5984/demo \
-d '{"item": "orange","prices": {"Fresh Mart": 1.99,
"Price Max": 3.19,
"Citrus Circus": 1.09}}'
curl -H 'Content-Type: application/json' -X POST http://127.0.0.1:5984/demo \
-d '{"item": "banana","prices": {"Fresh Mart": 1.99,
"Price Max": 0.79,
"Banana Montana": 4.22}}'
它使用以下地图显示所有项目:
function(doc) {
var shop, price, key;
if (doc.item && doc.prices) {
for (shop in doc.prices) {
price = doc.prices[shop];
key = [doc.item, price];
emit(key, shop);
}
}
}
但它会多次显示所有项目:
如何编写只显示每个项目最便宜的供应商的reduce函数?我怎样才能找到“哪里可以买到最便宜的苹果?”的答案。问题
答案 0 :(得分:1)
reduce函数不是正确的工具。该问题的答案是另一个地图功能。以下map函数完成了这项工作:
Find
The blog Custom API in Azure Mobile Services – Client SDKs
from MSDN