Table of Contents
In Couchbase 2.0 you can index and query JSON documents using views. Views are functions written in JavaScript that can serve several purposes in your application. You can use them to:
Find all the documents in your database that you need for a particular process,
Create a copy of data in a document and present it in a specific order,
Create an index to efficiently find documents by a particular value or by a particular structure in the document,
Represent relationships between documents, and
Perform calculations on data contained in documents. For example, if you use documents to represent users and user points in your application, you can use a view to find out which ten users have the top scores.
This chapter will describe how you can do the following using Couchbase SDKS and view functions:
Extract and order specific data,
Creating an index and use it to perform efficient document lookups,
Retrieve a range of entries, and
Perform a reduce function, which computes a value based on entry values.
This section is not an exhaustive description of views and managing views with Couchbase Server; it is merely a summary of basic concepts and SDK-based examples to start using views with Couchbase SDKs. For more detailed information about views, managing views, and handling views using Couchbase Web Console, see Couchbase Server Manual: Views and Indexes. To see examples and patterns you can use for views, see Couchbase Views, Sample Patterns