我的國家的名單:排序大洲
"country": [
{
"countryCode": "AD",
"countryName": "Andorra",
"currencyCode": "EUR",
"population": "84000",
"capital": "Andorra la Vella",
"continentName": "Europe",
"continent": "EU",
"areaInSqKm": "468.0",
"languages": [
"ca"
]
},
{
"countryCode": "AE",
"countryName": "United Arab Emirates",
"currencyCode": "AED",
"population": "4975593",
"capital": "Abu Dhabi",
"continentName": "Asia",
"continent": "AS",
"areaInSqKm": "82880.0",
"languages": [
"ar-AE",
"fa",
"en",
"hi",
"ur"
]
},
etc.
現在我必須寫的Map/Reduce的JSON函數來得到這樣的輸出:
重點:非洲的價值:xxx 關鍵:亞洲價值:xxx 等
其中'價值'代表每個大陸的國家數量。
我已經嘗試過這種地圖功能:
function(doc) {
var a
{
for (a in doc.country){
emit(doc.country[a].continentName, 1)
};
}
}
您使用哪種語言?你嘗試了什麼? –
@MJM:訂購json對象時要小心。遵從文檔和這個[問題](http://stackoverflow.com/questions/3948206/json-order-mixed-up),它們是無序的。 – albert
@AlexanderPuchkov:我正在使用JSON。我只是添加了我目前的功能。 – MJM