Couchbase:如何通过同步功能删除文档的频道访问权限

Couchbase: How to remove channel access for a document through Sync function

我是 Couchbase 的新手。我想通过同步功能更新一些文档的频道。但是现在,它不是在更新,而是在文档的元数据中添加了一个额外的频道,但没有删除现有的频道。谁能建议我如何删除文档中的现有频道?

同步功能:

function(doc, oldDoc) {
  //....
  if (doc.docType === "differentType") {
    channel("differentChannel");
    expiry(2332800);
    return;
  }
  //.......
}

文档:

{
  "channels": [
    "abcd"
  ],
  "docType": "differentType",
  "_id" : "asjnc"
}

元数据:

{
  "meta": {
    "id": "asjnc",
    "rev": "64-1b500000000",
    "expiration": 1650383285,
    "flags": 0,
    "type": "json"
  },
  "xattrs": {
    "_sync": {
      "rev": "1-db30e607872",
      "sequence": 777,
      "recent_sequences": [
        777
      ],
      "history": {
        "revs": [
          "1-db30e607872"
        ],
        "parents": [
          -1
        ],
        "channels": [
          [
            "differentChannel"
          ]
        ]
      },
      "channels": {
        "differentChannel": null
      }
    }
  }
}

期望文档具有相同的元数据:

{
  "channels": [ ], // <--- no channels
  "docType": "differentType",
  "_id" : "asjnc"
}

使用此同步功能,对于differentType类型的文档,频道differentChannel设置在metadataxattrs部分。但是之前从 couchbaseLite 添加的频道没有被删除。有人可以帮忙吗?

我在 Couchbase 论坛上回答了这个问题:https://forums.couchbase.com/t/remove-channels-from-a-document/33212

The "channels" property in a document is counter-intuitively not describing what channels the document is currently in - it's just a user-definable field that happens to be the default routing for channels if you don't specify a sync function. It's up to the writer of the document what it should contain.

If you have another means of channel assignments (like "docType" in your case), then you don't need to specify "channels" in the document. The sync metadata shows that the document is in "differentChannel" at revision 1-db30e607872 but the contents of the document can be arbitrary.