what happened on synced documents when the channel be changed?

37 views
Skip to first unread message

atom992

unread,
May 5, 2015, 3:53:49 PM5/5/15
to mobile-c...@googlegroups.com
Hi,all
    I am using Couchbase Lite 1.0.4 on Android and sync gateway 1.0.4.

    I have a question about sync gateway's channel.If I have a user U with role "role1",document A set : access(doc._id,"role1"). and I have sync the document A with user U. I want to know that If the user's role "role1" has been removed. what happend on my couchbase Lite with document A? will document A be removed(that what I want to do)?

    at the same time, I have another question about sync. My sync function based on document A's property P1, If document A have property P1 with the specified value,user B(can be queried by document A) will assign channel1. If document A's property P1 have been removed ,user B should not assign channel1.how should I do to remove channel1 from user B when document A's property P1 have been removed?

Jens Alfke

unread,
May 5, 2015, 4:17:51 PM5/5/15
to mobile-c...@googlegroups.com

> On May 5, 2015, at 12:53 PM, atom992 <yangzi...@gmail.com> wrote:
>
> I want to know that If the user's role "role1" has been removed. what happend on my couchbase Lite with document A? will document A be removed(that what I want to do)?

Almost. It'll update document A to a revision with no properties except for "_removed":true.

> at the same time, I have another question about sync. My sync function based on document A's property P1, If document A have property P1 with the specified value,user B(can be queried by document A) will assign channel1. If document A's property P1 have been removed ,user B should not assign channel1.how should I do to remove channel1 from user B when document A's property P1 have been removed?

I'm not quite sure I understand the question. If the sync function evaluating document A calls access( ) to grant user B access to a channel, and then the next time document A is updated the sync function doesn't grant user B access, then user B will no longer have access to the channel. (Unless there is another document that still gives her access, or her account's admin_channels gives her access, or she has a role that has access.)

Basically, every document in SG has metadata containing a list of user-to-channel grants. That list is rebuild from scratch every time the sync function runs. A user's access is computed by merging together the grants from all current documents.

—Jens

atom992

unread,
May 5, 2015, 5:06:07 PM5/5/15
to mobile-c...@googlegroups.com
Thank you very much.
" It'll update document A to a revision with no properties except for "_removed":true. " does this mean that I can not obtain document A by view or by document A's ID? or I need add _removed is not true in my view or query?

the next time document A is updated the sync function doesn't grant user B access, then user B will no longer have access to the channel. ” If document A have 3 property, and each property determines user's channel. does this means i should write sync function like this:
if(document A have property P1 )
{access(user1,P1)}
if(document A have property P2 )
{access(user1,P2)}
if(document A have property P3 )
{access(user1,P3)}

if(document A removed property P1 )
{
  if(document A have property P2 )
    {access(user1,P2)}
  if(document A have property P3 )
    {access(user1,P3)}
}

if(document A removed property P2 )
{
  if(document A have property P1 )
    {access(user1,P1)}
  if(document A have property P3 )
    {access(user1,P3)}
}

if(document A removed property P3 )
{
  if(document A have property P1 )
    {access(user1,P1)}
  if(document A have property P2 )
    {access(user1,P2)}
}

Jens Alfke

unread,
May 5, 2015, 7:30:18 PM5/5/15
to mobile-c...@googlegroups.com

> On May 5, 2015, at 2:06 PM, atom992 <yangzi...@gmail.com> wrote:
>
> does this mean that I can not obtain document A by view or by document A's ID? or I need add _removed is not true in my view or query?

You can still get the document explicitly by its ID. But it probably won't show up in queries since it doesn't have other properties that your map function would look for.

> If document A have 3 property, and each property determines user's channel. does this means i should write sync function like this:
> if(document A have property P1 )
> {access(user1,P1)}
> if(document A have property P2 )
> {access(user1,P2)}
> if(document A have property P3 )
> {access(user1,P3)}

That's all you need. The part in red is unnecessary.

—Jens

Reply all
Reply to author
Forward
0 new messages