I am bit confused about Document Permissions and Subscription rules

Lets get started with bit of a context.

And it is working fine as expected. I can access those _user data whose who is currently logged in.

Lets gets to an actual Issue

I have two collection.

‘_articles’ and ‘_user_articles’ .

‘_articles’ contains the global data, like ’ title, description, content .

‘_user_articles’ holds user interaction on above _article, such as ’ likes, votes , notes etc’

_user_articles is set up as :

_user_articles : {
  objectID:,
  createdby: user_id,
  _article. : '_articles ' ( the global one )' (on atlas the object id of that _article is stored)
  _vote : ,
  flag: boolean , 
}

The document rule for _user_articles is as :

"document_filters": {
        "write": {
          "createdby": "%%user.id"
        },
        "read": {
          "createdby": "%%user.id"
        }
      }

such that the user who created the _user_article can only access that _user_Article.

For now I am maintaining '_user_list field for ‘_articles’ and defining the sync rules such that if _user_list on ‘_Articles’ contains logged in user id, then that _articles gets accessible on local.

I dont know if this is the correct practice.

Another thing

The _user_article has flag value boolean, and _article filed which holds’_articles’ . If the 'flag field is true in ‘_user_article’ I want '_article ’ of same ‘_article’ to be accessible locally. Is there any better way to achieve this?

Hi @Shreedhar_Pandey!
As I see you are only missing the subscriptions. Use Realm Flutter SDK and open a Synced Realm. Then subscribe for you data that you need to have locally. Once you subscribe, the data will be downloaded and they will be synced in future if there are new changes. Define your filter criteria in the subscriptions. If you have added already permissions rules on the server for _user_articles by user.id, you don’t need to have a filter in the subscription by user articles. Just add one subscription for realm.all<User_articles>. Then add second subscription for the articles filtered according to your logic.

@Desislava_St_Stefanova
Thanks for Responding.
I have already opened a synced realm, the data is syncing fine.

I am trying to find a way to write subscription for ‘_articles’ based on the value of field in ‘_user_articles’ .

Each ‘_user_articles’ has field ‘article’ which references to a ‘_articles’ doc.

My current subscription query looks like.

mutableSubscriptions 
..add(
    realmHelper.query<Articles>(''' user_lists == $loggedInuserID '''),
)

So, if the user_lists field on ‘Articles’ contains my userID, it is synced to my local realm .

Can I do something like, query to my '_user_articles ’ and each ‘_user_articles’ has ‘_articles’ in them, and a boolean flag value. List out ‘_articles’ form ‘_user_articles’ whose flag value is true and sync those ‘_articles’ only ?