Search code examples
couchbasecouchbase-litecouchbase-sync-gateway

CouchBase Sync Gateway synchronizing


From: Couchbase Sync Gateway

I have some questions of the same subject.

Since last answer, things change and there is a tutorial for sync user data

https://docs.couchbase.com/userprofile-couchbase-mobile/current/userprofile/userprofile_sync.html

This example show how to sync only one document per user (like user profile), so only one bucket is needed for all user.

So my question:

In case of multiple documents per user (like a list of event), do I need to create a bucket per user? Or can I use the same way as the example?

Using channel is a good idea? https://docs.couchbase.com/sync-gateway/current/channels.html

Also, what can be the size/usage of the database for this?

Thanks

François


Solution

  • Channels is the right answer here. You could add an attribute called "channels" to your document:

    {
      username: "John"
      channels: ["john_channel_id_here", "someOtherOptionalChannel"]
    }
    

    And on your mobile app, after you authenticate the user called "John", you could subscribe to the channel "john_channel_id_here".

    If the document has an attribute called "channels", it will automatically put it on the channels described in the array. It is an easy way to add support for dynamic channels.

    There are more complex ways of how you can use channels, but this approach is good enough to get started.