Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library C (libcouchbase) 2.0
Community Wiki and Resources
Wiki: C and C++ Client Library
Download Client Library (source)
C and C++ Client Library
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
Couchbase Client Library C (libcouchbase) 2.0
Chapters

Chapter 5. View/Query Interface

Couchbase Enterprise 2.0 Server combines the speed and flexibility of Couchbase databases with the powerful JSON document database technology of CouchDB into a new product that is easy to use and provides powerful query capabilities such as 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 on Views, how they operate, and how to write effective map/reduce queries, see Couchbase Server 2.0: Views and Couchbase Sever 2.0: Writing Views.

The libcouchbase API provides direct access to Couchbase Views, while abstracting away the details about where in the cluster the views are to be executed. It is callback oriented and allows the caller to handle data streamed back from the Couchbase cluster in HTTP chunked encoding. The entry point to the libcouchbase view API is through the libcouchbase_make_couch_request() function.

For example, to range query a view looking for all keys starting with "I" through "j", one would execute a query similar to the following:

const char path[] = "myview?startkey=I,endkey=j";
libcouchbase_make_couch_request(instance, NULL, path, npath
                                NULL, 0, LIBCOUCHBASE_HTTP_METHOD_GET, 1);

This is derived from the libcouchbase interface:

libcouchbase_couch_request_t libcouchbase_make_couch_request(libcouchbase_t instance,
                                                                const void *command_cookie,
                                                                const char *path,
                                                                libcouchbase_size_t npath,
                                                                const void *body,
                                                                libcouchbase_size_t nbody,
                                                                libcouchbase_http_method_t method,
                                                                int chunked,
                                                                libcouchbase_error_t *error);

Where:

For additional usage on this API, please refer to the examples in the source code repository at Couchbase Sever 2.0: Writing Views