API

The main way to query data from CouchDB is through the REST API.

URI

The URI to query to get a view’s result is /<database>/_design/<designdocname>/_view/viewname

Query Params

we can add query params to narrrow the result, which is how we'd achieve similar things to using the WHERE clause in SQL:

  • ?key="2009/01/30 18:04:11"
  • ?startkey="2010/01/01 00:00:00"&endkey="2010/02/00 00:00:00" (inclusive range)

We can sort the results by multiple fields by using an array as a key, since results are always sorted by key.

  • ?startkey=["myslug"]&endkey=["myslug", 2]

We can sort by descending order

  • ?descending=true

We can include the full body of each document in the results

  • ?include_docs=true