I have a list of countries:
"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.
Now I have to write a Map/Reduce function in JSON to get an output like this:
Key: Afrika Value: xxx Key: Asia Value: xxx Etc.
Where 'value' represents the amount of countries in each continent.
I already tried this Map function:
function(doc) {
var a
{
for (a in doc.country){
emit(doc.country[a].continentName, 1)
};
}
}
I recommend to emit the value
null
instead of1
and use the built-in reduce function_count
.