CBL replication change account

41 views
Skip to first unread message

Felix

unread,
Jun 19, 2014, 3:25:21 PM6/19/14
to mobile-c...@googlegroups.com
Hi, 

I am building an Android App using CBL with both continuous pull and push replication from SyncGateway. There is one story case that I can not find correct way to implement.

User1 starts the app and logs in,  both "public" channel and "user1" channel documents are pulled to CBL from sync-gateway. User1 log outs from the app and User2 logs in on the same device.  I hope that "public" channel will not be deleted when user1 logs out and thus only "user2" channel documents will need to be pulled from sync-gateway when user2 logs in.

I tried to implement with Replication.stop() and Document.purge() to purge only "user1" channels in local CBL when user1 logs out. However, when user1 logs in again on the same device, "user1" channel will not be pulled from sync-gateway.

Any suggestions?

Thanks.





Jens Alfke

unread,
Jun 19, 2014, 3:58:35 PM6/19/14
to mobile-c...@googlegroups.com

On Jun 19, 2014, at 12:25 PM, Felix <hufe...@gmail.com> wrote:

User1 starts the app and logs in,  both "public" channel and "user1" channel documents are pulled to CBL from sync-gateway. User1 log outs from the app and User2 logs in on the same device.  I hope that "public" channel will not be deleted when user1 logs out and thus only "user2" channel documents will need to be pulled from sync-gateway when user2 logs in.

If you support multiple user logins with different documents available, you need to have a separate database for each user. Couchbase Lite itself does not have any notion of permissions or access controls within a database.

I tried to implement with Replication.stop() and Document.purge() to purge only "user1" channels in local CBL when user1 logs out. However, when user1 logs in again on the same device, "user1" channel will not be pulled from sync-gateway.

Yes, this is one of the common ways that people get burned using purge. Purge just completely forgets about the document locally. The document won’t be downloaded again on the next replication, because it hasn’t changed since the last pull. The way pull works is that the client asks the server for documents that have changed since the last time it pulled, and then downloads them.

I understand what you’re trying to do, and it makes sense, but it’s not supported by CBL as it exists today. That’s largely because CBL’s replication model is based on CouchDB, which is a server and as such doesn’t really have a use for things like syncing and then forgetting and then re-syncing sets of documents. In the future we’re going to be extending CBL to handle some of these other replication workflows that are useful on mobile devices.

For now I’d suggest having two databases instead of using purge. (Also, does your app itself really need to handle multiple logins? Android itself has multi-user support, which I think will provide a separate data directory for the app depending on which user is logged in, so your app shouldn’t have to worry about it.)

—Jens
Reply all
Reply to author
Forward
0 new messages