Search:

Search all manuals
Search this manual
Manual
Couchbase Server Manual 2.0
Community Wiki and Resources
Download Couchbase Server 2.0
Couchbase Developer Guide 2.0
Client Libraries
Couchbase Server Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
9.9 View and Query Pattern Samples
Chapter Sections
Chapters

9.9.4. Secondary Index

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:

JSON
{
    "firstname": "Martin",
    "lastname": "Brown"
}

A view to support queries on the firstname field could be defined as follows:

Javascript
function(doc, meta) 
{
  if (doc.firstname) 
  {
     emit(doc.firstname.toLowerCase(),null);
  }
}

The view works as follows for each document:

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.