How to allow editing some field in some collections MondoDB Realm?

Viewed 108

I need to allow write for all users in some field one of my collection

All my data save in MondoDB Atlas and I sync it in the "Sync" MongoDB Realm.

I have some troubles with my task

If in the rules "Sync" I set: read - true write - false and in the collection set these rules:

{
  "roles": [
    {
      "name": "default",
      "apply_when": {
        "%%true": true
      },
      "insert": false,
      "delete": false,
      "search": true,
      "read": true,
      "write": false,
      "fields": {
        "countViews": {
          "write": true
        },
        "listViewers": {
          "write": true
        }
      },
      "additional_fields": {}
    }
  ],
  "filters": [],

Then have this error: Sync: Connection[1]: Session[1]: Received: ERROR "Permission denied (BIND, REFRESH) - request logs URL: link” (error_code=206, try_again=true)

But if I set rules for sync: read - allow write - allow All users can write data in any fields and collection, despite the rules in the collection

So, I can't understand where I make mistake and what rules should I set in the Sync. Rules for Sync > rules for Collection? Or it's mistake in the rules for collection, that I wrote?

1 Answers

The issue is that document level write permissions take priority over field level ones.

The rules in your question have write: false

"roles": [
    {
      "name": "default",
      "apply_when": {
        "%%true": true
      },
      "write": false,   <- document level write is FALSE which takes priority

but then the field level rules are true but are overridden

"fields": {
   "countViews": {
      "write": true
   },

From the documentation

Document-level write permissions take priority over any field-level permissions. If a role has a document-level write rule, it applies to all fields in the document and cannot be overridden.

There are a number of solutions; omit the document level rule and specify the rules on the individual fields. Or add the 'additional_fields' rule to blanket apply a rule to fields you don't supply rules for.

"additional_fields": { "write": true }
Related