There are some general points and advice for writing all views that apply irrespective of the document structure, query format, or view content.
Do not assume the field will exist in all documents.
Fields may be missing from your document, or may only be
supported in specific document types. Use an
if test to identify problems. For
example:
if (document.firstname)...View output is case sensitive.
The value emitted by the emit()
function is case sensitive. Emitting a field value of
'Martin' but specifying a key value of
'martin' will not match the data. Emitted data, and the key
selection values, should be normalized to eliminate
potential problems. For example:
emit(doc.firstname.toLowerCase(),null);Number formatting
Numbers within JavaScript may inadvertently be converted and output as strings. To ensure that data is correctly formatted, the value should be explicitly converted. For example:
emit(parseInt(doc.value,10),null);
The parseInt() built-in function will
convert a supplied value to an integer. The
parseFloat() function can be used for
floating-point numbers.