【问题标题】:Getting all subitems from all documents with a Couchbase map/reduce view使用 Couchbase map/reduce 视图从所有文档中获取所有子项
【发布时间】:2020-04-09 04:31:04
【问题描述】:

我的 Couchbase 文档的结构如下:

{
  "subscriberIds": [
    {
      "type": "END_USER",
      "identity": "00000000223"
    }
  ],
  "userDataId": "SUB-00000000223",
  "status": "ACTIVATED",
  "subscriptions": [
    {
      "id": "Something1",
      "attributes": [
        {
          "value": "Active",
          "name": "Status"
        }
      ],
      "priority": "1",
      "subscriptionStartDate": somedate,
      "productShortName": "Something1"
    },
    {
      "id": "Something2",
      "attributes": [
        {
          "value": "Active",
          "name": "Status"
        }
      ],
      "priority": "1",
      "subscriptionStartDate": somedate,
      "productShortName": "Something2"
    }
  ],
}

我正在尝试编写一个视图以从存储桶中的所有文档中获取所有“订阅”:

{"total_rows":900,"rows":[
{"id":"Something1","key":null,"value":"00000000223"},
{"id":"Something2","key":null,"value":"00000000223"},
...

但是,我无法从文档中获取嵌套项

function (doc, meta) {
  for (var i in doc.subscriptions) {
    emit(doc.subscriptions.id, doc.id);
  }
}

我知道这是可能的,但显然我并不完全理解视图的概念。

【问题讨论】:

    标签: couchbase couchbase-view


    【解决方案1】:
    for (var i in doc.subscriptions) {
        emit(doc.subscriptions[i].id, doc.id);
    }
    

    【讨论】:

    • 口头解释通常很有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    相关资源
    最近更新 更多