Mind that:
- CouchDB function
emit()
takes two parameters, first is a key (eg."category1"
), second is a value (eg.5
). See the view API documented in the CouchDB wiki. [key:val, ...]
is not correct JSON field syntax, did you mean list of single field records ([{"key1": val1}, {"key2": val2}, ...]
) or single multi-field record ({"key1": val1, "key2": val2, ...}
)?- In case of
"name": [{ "category1": 5}, {"category2": 8 }]
argument offorEach
continuation is{"category1": 5}
, and you should get somehow"category1"
and5
separately (forEach()
orfor (var key in sth) {}
once more??). - In case of
"name": { "category1": 5, "category2": 8 }
, remember the JS object ({"field": val, ...}
) does not haveforEach
method, array ([val1, val2, ...]
) prototype does.
Assuming you meant "name": { "category1": 5, "category2": 8 }
as the name, consider trying the following map
:
function (data) {
if (date.name) {
for (var sth in name) {
emit(sth, name[sth]);
}
}
}
If you are JavaScript beginer, try writing proper code in console first. You can use the one found in the web-browser (Firefox, Chrome have build-in, I advise FireBug addon for Firefox). Good luck!