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.3. Document ID (Primary) Index

To create a 'primary key' index, i.e. an index that contains a list of every document within the database, with the document ID as the key, you can create a simple view:

Javascript
function(doc,meta) 
{
  emit(meta.id,null);
}

This enables you to iterate over the documents stored in the database.

This will provide you with a view that outputs the document ID of every document in the bucket using the document ID as the key.

The view can be useful for obtaining groups or ranges of documents based on the document ID, for example to get documents with a specific ID prefix:

?startkey="object"&endkey="object\u0000"

Or to obtain a list of objects wtihin a given range:

?startkey="object100"&endkey="object199"

Note

For all views, the document ID is automatically included as part of the view response. But the without including the document ID within the key emitted by the view, it cannot be used as a search or querying mechanism.