With Couchbase Server 2.0, you can add the power of views and querying those views to your applications.
Create a view object to be used when querying a view:
Parameters:
String ddocname |
Design document name |
String viewname |
View name within a design document |
Then create a new query object to be used when querying the view:
Once, the view and query objects are available, the results of the server view can be accessed using
Parameters:
View view |
View object associated with a server view |
Query query |
Query object associated with a server view |
Before accessing the view, a list of options can be set with the query object:
query.setKey(String key)to set the key to query in the view
query.setKey(ComplexKey key)to set the key to query in the view
query.setRangeStart(String startKey)to set the starting key
query.setRangeStart(ComplexKey startKey)to set the key to query in the view
query.setKey(String key)to set the starting key
query.setRangeEnd(String endKey)to set the key to query in the view
query.setRangeEnd(ComplexKey endKey)to set the ending key
query.setRange(String startKey, String endKey)to set a range
query.setRange(ComplexKey startKey, ComplexKey endKey)
query.setDescending(boolean descending)to sort in descending order
query.setIncludeDocs(boolean include)to include the JSON doc
query.setReduce(boolean reduce)execute the reduce function
query.setStale(Stale reduce)set to OK will not refresh the view even if it is stale, set to UPDATE_AFTER will update the view after the stale result is returned, FALSE will update the view and return the latest results.
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 an 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.
Ruby