No data replicated from SG->CBL (iOS) with `documentIDs` option

I’m moving from a Cloudant server to Couchbase + Sync Gateway. I’m having trouble pulling data down. Initially, I am just trying to pull a small subset in so that I can then add the mydb.cblite2 as a prebuilt database. I’m doing this by specifying a number (17) of document IDs to the documentIDs option. At least it has the number right!

However I can’t see any data. Turning on logging, I can see a few bad_request responses, but not sure what they mean. Any clues?

16:55:10.647‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words]: Server is Couchbase Sync Gateway/1.4.0
16:55:10.650| Sync: CBLReplication[from http://<sg-ip>:4984/sayit-words]: active, progress = 0 / 17, err: (null)
16:55:10.650‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words]: Caught up with changes!
16:55:10.652‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words] queued 17 remote revisions from seq=3860 (17 in bulk, 0 individually)
16:55:10.652‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words] bulk-fetching 17 remote revisions...
16:55:11.600‖ CBLSocketChangeTracker[0x7ff9cf20 sayit-words]: Can't connect, giving up: CBLHTTP[400, "bad_request", <http://<sg-ip>:4984/sayit-words/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=74268&filter=_doc_ids>]
16:55:11.600‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words]: ChangeTracker stopped; error=CBLHTTP[400, "bad_request", <http://<sg-ip>:4984/sayit-words/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=74268&filter=_doc_ids>]
16:55:11.600‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words] Progress: set error = CBLHTTP[400, "bad_request", <http://<sg-ip>:4984/sayit-words/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=74268&filter=_doc_ids>]
16:55:11.600‖ Sync: CBLRestPuller[http://<sg-ip>:4984/sayit-words] STOPPING...
16:55:11.600‖ Sync: CBLRestPuller[http://<sg-ip>/sayit-words] Progress: 17 / 17
16:55:11.600‖ Sync: CBLRestPuller[http://<sg-ip>/sayit-words] Progress: set active = 0
16:55:11.600‖ Sync: CBLRestPuller[http://<sg-ip>/sayit-words] STOPPED
16:55:11.601‖ Replication: CBLRestPuller[http://<sg-ip>/sayit-words] took 1.152 sec; error=CBLHTTP[400, "bad_request", <http://<sg-ip>/sayit-words/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=74268&filter=_doc_ids>]
16:55:11.601| Sync: CBLReplication[from http://v:4984/sayit-words]: stopped, progress = 17 / 17, err: CBLHTTP[400, "bad_request", <http://<sg-ip>:4984/sayit-words/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=74268&filter=_doc_ids>]
2017-09-15 16:55:11.601 [info][tid:com.facebook.react.JavaScript] sayit pull event: 17 / 17

Ok, so I am using channels, and upon setting the channel I am now getting data pulled down… but all of it!! Is it possible to use the documentIDs param alongside channels? Should I set a filter on the server instead? The given subset is not in a different channel, its a small subset of one of the channels.

If there is some property that uniquely identifies the 17 documents of interest , you can use that as the criteria for assigning documents to channels using the channel call.
Example , lets say you have a “type” property that uniquely identifies the documents of interest

  var type = getType();
  if (type == "interesting") {
         // Add doc to the type channel.
         channel("channel."+ type );    

       // Give user access to channel
        access(username,"channel." + type)

 function getType() {
    return (isDelete() ? oldDoc.type : doc.type);
1 Like

Just use documentIDs if you know the exact docs you want. There’s no need to specify channels too, it would be redundant.

Should I set a filter on the server instead?

Sync Gateway doesn’t support CouchDB-style server-side filters. They’re not scaleable, because the filter code has to be run once per document per user. Channels were designed as a replacement for this.

1 Like

I assume this code would be with the sync property of the Sync Gateway config? I was wondering how to add another property as part of a channel. So something like this:

      "sync" : `function(doc) {
        if (doc.category == "free")    
          channel("free")  // Mark doc for inclusion in initial dataset to be bundled with app
        channel(doc.wordlist);  // Current contents of sync function

I wasn’t sure if the channel function could be called more than once…

Yes that code would be part of sync gateway config.
In your example , the document would be added the “free” and “doc.wordlist” channel.
The channel method takes in a single channel or an array of channels