GET /{db}/_changes

In this document

This request retrieves a sorted list of changes made to documents in the database, in time order of application, can be obtained from the database’s _changes resource. Only the most recent change for a given document is guaranteed to be provided. For example if a document has had fields added, and then deleted, an API client checking for changes will not necessarily receive the intermediate state of added documents.

This request can be used to listen for update and modifications to the database for post processing or synchronization. A continuously connected changes feed is a reasonable approach for generating a real-time log for most applications.

Request


Request headers

This request does not have any required headers.

Query parameters

NameTypeDescriptionDefault
attachmentsBooleanIndicates whether to include the Base64-encoded content of attachments in the documents that are included when include_docs is true. this parameter is ignored when include_docs is false.false
att_encoding_infoBooleanIndicates whether to include encoding information in attachment stubs when include_docs is true.false
conflictsBooleanIncludes conflicts information in response. Ignored if include_docs isn’t true.false
descendingBooleanReturn the change results in descending sequence order (most recent change first).false
doc_idsarrayList of document IDs to filter the changes feed as valid JSON array. Used with _doc_ids filter.none
feedstringSpecifies type of change feed. Valid values: normal, continuous, eventsource, longpollnormal
filterstringReference to a filter function from a design document that will filter whole stream emitting only filtered events.none
heartbeatintegerPeriod in milliseconds after which an empty line is sent in the results. Only applicable for longpoll or continuous feeds. Overrides any timeout to keep the feed alive indefinitely.60000
include_docsBooleanIndicates whether to include the associated document with each result. f there are conflicts, only the winning revision is returned.false
last-event-idintegerAlias for the Last-Event-ID header.none
limitintegerLimits the number of result rows to the specified value. Using a value of 0 has the same effect as the value 1.none
sinceintegerStarts the results from the change immediately after the given sequence number. The value can be an integer or a row value.0
stylestringNumber of revisions to return in the changes array. main_only returns the current winning revision, all_docs returns all leaf revisions including conflicts and deleted former conflicts.main_only
timeoutintegerMaximum period in milliseconds to wait for a change before the response is sent, even if there are no results. Only applicable for longpoll or continuous feeds. The default value is specified by the httpd/changes_timeout configuration option. If not specified, the default maximum timeout is used to prevent undetected dead connections.60000
viewstringName of a view function to use as a filternone

Response


Status codes

Response headers

This response uses only standard HTTP headers.

Message body

The response message body contains a JSON document with the following objects;

NameTypeDescription
last_seqintegerLast change sequence number
resultsarrayList of changes to the database. See the following table for a list of fields in this object.

The results array contains the following objects:

NameTypeDescription
changesarrayList of the document’s leafs. Each leaf object contains one field, rev.
idstringDocument identifier
seqintegerUpdate sequence number

Example


The following example requests the changes to the database named cookbook and specifies that only two rows be included in the response:

Request

GET /cookbook/_changes?limit=2 HTTP/1.1
Host: localhost:59840

Response

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: must-revalidate
Content-Type: application/json
Date: Mon, 16 Dec 2013 21:09:35 GMT
Etag: "13"
Server: CouchbaseLite 1.486
Transfer-Encoding: chunked
{
  "results" : [
    {
      "seq" : 1,
      "id" : "A329CFEC-29E8-4DCF-BB49-EFCE8CD6B212",
      "changes" : [
        {
          "rev" : "1-afbf905396a144446feb2431c37065f9"
        }
      ]
    },
    {
      "seq" : 2,
      "id" : "209BB170-C1E0-473E-B3C4-A4533ACA3CDD",
      "changes" : [
        {
          "rev" : "1-ed0ebedd2fab89227b352f6455a08010"
        }
      ]
    }
  ],
  "last_seq" : 2
}