Search code examples
laravelcouchbasecouchbase-sync-gateway

How to filter data by channel in config file of sync gate way in Couchbase?


I connected to sync gate way via Api ,but I don't know how to filter some data and use them in my laravel project.


Solution

  • You are not filtering by channel in the syncgateway config, the filtering is the outcome of the sync-function, but it is more of a passive result of attaching a channel to a document. I have no idea which version you are using because your question lacks it, however configuration is pretty straight forward.

    you basically have 2 options of attaching a channel to a document, the second is overriding the first: 1. don't have any sync function in the config file and just rely on a "channels" property, that property will make the document sync to the appropriate channels. for example:

    { "name": "Duke", "lastName": "Nukem", "channels": ["DukeNukem","Duke"] }
    

    2. Have a sync function in the config file: For the document: { "name": "Duke", "lastName": "Nukem" }

    you might have that sync function that will do the same:

    function(doc, oldDoc){
       if (doc.name && doc.lastName) {
            channel(doc.name);
            channel(doc.name + doc.lastName);
        }
    }
    

    please note that you will have to grant permission to the user to able to see a channel.

    in the client side you would need that user with the permission, and if you are not filtering for a channel - you will get the docs whenever you sync.

    please read more here