Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.1
Community Wiki and Resources
Download Client Library
JavaDoc
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
Java Client Library
SDK Forum
Wiki: Java Client Library
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
Couchbase Client Library: Java 1.1
Chapters

Chapter 10. View/Query Interface

Couchbase Server 2.0 extends the querying mechanisms by not only allowding key-based lookups, but also allowing you to query your datasets through a flexible mechanism called views. Those views are based on a common data aggregation approach called map/reduce. With Couchbase Server 2.0 you are able to keep using all of the Couchbase code you already have, and upgrade certain parts of it to use JSON documents without any hassles. In doing this, you can easily add the power of Views and querying those views to your applications.

For more information about using views for indexing and querying from Couchbase Server, here are some useful resources:

The View Object is obtained by calling the getView method which provides access to the view on the server.

API Callclient.getView(ddocname, viewname)
Asynchronousno
Description Create a view object to be used when querying a view.
Returns(none)
Arguments 
String ddocname Design document name
String viewname View name within a design document
View view = client.getView(docName, viewName)

Then obtain a new Query object.

API CallQuery.new()
Asynchronousno
Description Create a query object to be used when querying a view.
Returns(none)
Arguments 
 None  
Query query = new Query();

Once, the View and Query objects are available, the results of the server view can be accessed as below.

API Callclient.query(view, query)
Asynchronousno
Description Query a view within a design doc
Returns(none)
Arguments 
View view View object associated with a server view
Query query View object associated with a server view
ViewResponse = client.query(view, query);

Before accessing the View, a list of options can be set with the query object (here is a short list of the most commonly used ones).

The format of the returned information of the query method is:

ViewResponse or any of the other inherited objects such as ViewResponseWithDocs, ViewResponseNoDocs, ViewResponseReduced.

The ViewResponse method provides a iterator() method for iterating through the rows as a ViewRow interface. The ViewResponse method also provides a getMap() method where the result is available as a map.

The following methods are available on the ViewRow interface.

For usage of these classes, please refer to the Chapter 2, Tutorial which has been enhanced to include Views.