_changes API not working with filter and view parameters in Couchbase Lite

The _changes document is not clear on the filter and view parameters, in Couchbase Lite. I am trying to query the below url to fetch changes if a document with type order gets added.

_changes?include_docs=true&feed=longpoll&since=0&filter=_view&view=orders%2Forder

This filter=_view&view=orders%2Forder query parameter is the issue, removing the same from the above fetches all the documents

Using the above gives a 404 on Couchbase Lite but the same works on CouchDB.
Response:

{
    status: 404,
    error: "not_found"
}

Here is my _design/orders

{
     "_id": "_design/orders",
     "language": "javascript",
     "views": {
          "order": {
               "map": "function(doc) {if(doc.type && doc.type == 'order') {emit(doc.oID, doc);}}"
           }
      }
}

Please can you share the syntax or example on how to pass the design document and/or view in _changes API.

Just to add some details on this thread. Here’s the list of API calls to reproduce the issue:

Start the listener with LiteServ: LiteServ --port 5984

// Create database
PUT /skybook/ HTTP/1.1
Host: localhost:5984
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest
Content-Length: 0

// Create doc that will get returned by the filter function
POST /skybook/ HTTP/1.1
Content-Type: application/json
Host: localhost:5984
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest
Content-Length: 34

{"type":"order","SeatNumber":"10"}

// Create doc that won't get returned by the filter function
POST /skybook/ HTTP/1.1
Content-Type: application/json
Host: localhost:5984
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest
Content-Length: 28

{"type":"user","Name":"ali"}

// Register view queries
PUT /skybook/_design/orders HTTP/1.1
Content-Type: application/json
Host: localhost:5984
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest
Content-Length: 113

{"views": {"order": {"map": "function(doc) {if(doc.type && doc.type == 'order') {emit(doc.SeatNumber, doc);}}"}}}

// Query the changes feed with map function as the filter
GET /skybook/_changes?filter=_view&view=orders/order&since=0 HTTP/1.1
Host: localhost:5984
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest

--> Returns 404 not found

// Query view returns the expected result
GET /skybook/_design/orders/_view/order HTTP/1.1
Host: localhost:5984
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest

Specifying a filter function in the design document or using the map function as the filter returns the same status code, 404 not found.

@jens Do you know if we support map functions as filters for the changes feed on the Listener API?

James

This is a fundamental difference between sync gateway and couchdb. Whereas couchdb elects to filter and map things at request time, sync gateway elects to filter and map things at write time via channels.

Yes absolutely but actually in this case I was talking about the CBL REST API. This endpoint could be used in a Couchbase Lite + Cordova Plugin scenario to be notified of changes that effect a particular view query to refresh the corresponding portion of the UI.

If that’s not supported then the workaround could be to listen on the changes feed and have some business logic there to re-run the necessary view query based on the document type?

James

I’m pretty sure we haven’t implemented the ?filter=_view mode of CouchDB in the CBL REST API. You can file an issue on Github to request it.

In the document of Couchbase Lite _changes, filter and view parameters is mentioned but there is no example or syntax are given for the same.

http://developer.couchbase.com/documentation/mobile/current/develop/references/couchbase-lite/rest-api/database/get-changes/index.html