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.
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?
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?