0

I want to pull documents with username attribute as user1 for user1 like that for each user only attribute with their name.

This is my replication code.

   private void setupreplication(){
         Console.WriteLine ("Setting up replication");
         Uri Server = new Uri("http://192.168.1.213:4984/aussie-coins-syncgw/");
         var pull = _db.CreatePullReplication (Server);
         var push = _db.CreatePushReplication (Server);
         pull.Filter = "byUser";
         pull.FilterParams = new Dictionary<string, object> { {"type", "user1"} };
        pull.Continuous = true;
        push.Continuous = true;
        pull.Start();
        push.Start();
    }

This is my set filter code

_couchBaseLiteLocal.SetFilter("byUser", (revision, filterParams) =>
            {
                var typeParam = filterParams["type"].ToString();

                return (typeParam != null) && typeParam.Equals("user1");
            });

With the above code generic pull itself not working. I just tried to do as given in the documentation.

I do not understand how the setfilter function works to filter data from server. It would be great if someone help in understanding how setfilter works and to make the above code working

Thanks in advance.

1 Answers1

0

The filter function in pull replications can indeed return the specific documents you are interested in. But it's not very efficient, the filter function will run on all the documents on the remote database to determine which ones to pull, every time a pull replication is started.

Instead Sync Gateway introduces the concept of a sync function that incrementally routes and computes access control rules on documents. That way, when starting the pull replication, it's fast and straightforward for Sync Gateway to return the specific documents the user has access to.

You can specify individual channels in a pull replication from Sync Gateway if needed. But the thing to remember is that filtered pull replication between Sync Gateway and Couchbase Lite is not based on filter functions. It's based on the sync function and channel based filtering if needed.

In a P2P scenario (replications between two Couchbase Lite instances), the filter function model is used.

jamiltz
  • 1,144
  • 8
  • 15