1

I am trying to sync pouchDB with CouchBase through Sync Gateway by channel. In pouch I have :

var da = new PouchDB('example_DE');
    da.sync(remoteDB, {
        create_target: true,
        live: true,
        retry: true,
        filter: "sync_gateway/bychannel",
        query_params: {
            channels: ["DE"]
        }
    })

Sync config file:

{
"log": ["*"],
"CORS": {
    "Origin":["http://127.0.0.1:8887","http://localhost:8887"],
    "LoginOrigin":["http://127.0.0.1:8887","http://localhost:8887"],
    "Headers":["Content-Type","Authorization"],
    "MaxAge": 1728000
},
"adminInterface": "127.0.0.1:4985",
"interface": "0.0.0.0:4984",
"databases": {
    "db": {
        "bucket":"db",
        "username": "Administrator",
        "password": "123456",
        "server": "http://localhost:8091",
        "sync":
            `function (doc) {
               channel(doc.channels);
            }
            `,
        "users": {
            "GUEST": {"disabled": false, "admin_channels": ["*"] }
        }
    }       
}

I can find in browser in IndexedDB my documents but in console I get this error: GET http://localhost:4984/db/_local/nKlC5IrimnHOiQZcwE_LYA%3D%3D? 404 (Not Found)

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • What versions of Pouch, Sync Gateway, and Couchbase Server are you using? – Matthew Groves Mar 14 '18 at 17:21
  • 1
    PouchDB - 6.4.3, Sync Gateway - 1.5, Couhbase Server - Community Edition 5.0.1 – Andrey Shat Mar 14 '18 at 17:30
  • 1
    I suspect two issues here. First, if I understand PouchDB options correctly, you're asking for a server-side filter based on a design document. Have you set up a design doc in Sync Gateway? That could account for the 404 error. Second, there are compatibility issues with filtered replications. I don't know whether this would affect your case or not. You can read about the problem here: https://github.com/couchbase/couchbase-lite-ios/issues/1139 – Hod Mar 14 '18 at 20:11
  • 1
    What do you mean set up a design doc? I can see document in Sync Gateway in admin interface – Andrey Shat Mar 15 '18 at 14:00
  • Reviewing it further, I think I'm wrong. It looks like you're using the wrong endpoint to retrieve the document. If it has been synced from PouchDB, it should be http://localhost:4984/db/doc_id. See https://developer.couchbase.com/documentation/mobile/1.5/references/sync-gateway/rest-api/index.html#/document/get__db___doc_ _local is for special purpose docs. By design, they aren't replicated. (Just for reference on design docs, see: https://developer.couchbase.com/documentation/mobile/1.4/guides/sync-gateway/views/index.html) – Hod Mar 16 '18 at 00:59
  • Thank you for your reply. Request to endpoint with ..../_local generates PouchDB. I use only da.sync(...) in my code. If I use sync function without filter: "sync_gateway/bychannel" I don't have any error. – Andrey Shat Mar 16 '18 at 13:32

1 Answers1

0

Here is the way to do it without having the need to remove "sync_gateway/bychannel":

var local = new PouchDB("yep");
var remote = new PouchDB("http://user:password@localhost:4984/bucket/");

// sync starts here
local.replicate.from(remote, {
    filter: "sync_gateway/bychannel",
    query_params: {
        channels: ["DE"]
    }
});
Miko Chu
  • 1,087
  • 14
  • 22