Skip to content
Dominic Barnes edited this page May 21, 2014 · 1 revision

View(ddoc, name)

Represents a CouchDB view, and is used for querying map-reduce views.

var couchdb = require("couchdb-api");

// the URL used below is the default
var view = couchdb().db("mydb").ddoc("myddoc").view("myview");

View#url()

This helper method is for generating a String URL for the view.

view.url();
// => http://localhost:5984/mydb/_design/myddoc/_view/myview

View#query([params], callback)

GET /{db}/_design/{ddoc}/_view/{view} CouchDB Documentation

When only callback is included, it's a simple GET.

view.query(function (err, results) {
    // ...
});

POST /{db}/_design/{ddoc}/_view/{view} CouchDB Documentation

When params includes a keys option, it will use a POST to retrieve the specified keys. (all other options will be excluded)

view.query({ keys: [ "a", "b" ] }, function (err, results) {
    // ...
})

GET /{db}/_design/{ddoc}/_view/{view} CouchDB Documentation

In all other cases, the params will be sent as querystring arguments as part of the request.

view.query({ limit: 10, offset: 10, reduce: false }, function (err, results) {
    // ...
})
Clone this wiki locally