The simplest form of view is to create an index against a single field from the documents stored in your database.
For example, given the document structure:
{ "firstname": "Martin", "lastname": "Brown" }
A view to support queries on the firstname
field could be defined as follows:
function(doc, meta) { if (doc.firstname) { emit(doc.firstname.toLowerCase(),null); } }
The view works as follows for each document:
Only outputs a record if the document contains a
firstname field.
Converts the content of the firstname
field to lowercase.
Queries can now be specified by supplying a string converted to lowercase. For example:
?key="martin"
Will return all documents where the firstname
field contains 'Martin', regardless of the document field
capitalization.