UseCase: I have a document user_profile where i have like 10-15 fields. Now some of the user’s field are private and some of them are public and can be visible to anyone.
Now say someone wants to see this user profile but they should only see the public fields in this profile doc. In a regular no-sql app you can have a field called public_fields which is an array of all keys which are publicly visible. And then let the authentication layer filter the doc data and only pass forward the public fields to be shown on the app.
What is an idomatic way to do this through sync-gateway?
sync gateway sync document as the minimum unit. you can assign a document to a channel, then route the channel to some one.
one feasible way is split your user_profile to two document, public fields in one document,and private fields in another document.
I was thinking of the same, but the following are my concerns:
- if a field was earlier private and is now supposed to be public universally for all user_profiles, we have to update both the set of documents.
- if a field can be public for some and private for some, the query need to look in both the documents as you don’t know where it resides
- it becomes super complicated for nested objects. If the sharing can be partial in a nested deep object, we have to divide the sub-object between these two documents and then it require patching on the client side.
- it feels fundamentally wrong to divide the doc around sharing permissions.
may be you can split the fields into another document, and when the condition was reached, change the channel from private to public will avoid update both the set of documents.
how about reduced store fields into public document and private document?
the same solution: reduced store fields into public document and private document.