Get 400 Bad Request when doing pull replication with documentIds set

I’m using couchbase lite v1.0.4 iOS. For a pull replication object I called the setDocumentIds method and with an array of document id strings. I then tried to do the replication but it said 400 bad request for the replication, and sync gateway (v1.1.0) showed this error in the logs:

20:31:07.038407 2015-09-04T20:31:07.038Z HTTP: #1745:     --> 400 Unknown filter; try sync_gateway/bychannel  (2.9 ms)

How do I use the setDocumentIds method properly for a pull replication? Is there anything else I have to set with it?

Turns out you have to call setChannels: nil and setFilter: nil or else it will fail with a 400 bad request.

This is because server side filters are not supported on Sync Gateway. A set of document IDs is actually a special filter underneath. The reason it exists is for compatibility with CouchDB, which does support server side filters. So actually, by setting the filter to nil you cancelled the document ID filter. In exchange, Sync Gateway has a concept called “channels” which allow you to specify groupings for your documents.

It did seem to work though because it synced some documents. Are you saying that with couchbase and sync gateway I can’t use the document ids list in a pull replication? I will test some more to verify it is only retrieving the documents I specified and not just ignoring the documentIds and doing a full pull replication. I can’t use channels to filter because they are incredibly limited in terms of functionality, and I learned very painfully today that if you have too many sync gateway will slow to a crawl and become unusable. So the documentIds list was supposed to be my substitution for channel filtering since they simply aren’t usable for our use case.

Correct, document ID filtering is not implemented in Sync Gateway. The relevant issue is here. If you feel that it would be useful to you, I suggest putting some comments on the ticket to keep it visible. I know this has come up before from other people besides you and the more attention it gets the more likely it is to get a specific timeline for implementation.

I added a +1 for it. This is really disappointing. We’ll have to find a way to bypass sync gateway entirely when doing filtered replications.