【问题标题】:sub document under main document how to get a listing with pagination using couchbase(N1QL) query主文档下的子文档如何使用 couchbase(N1QL) 查询获取分页列表
【发布时间】:2020-03-30 14:38:19
【问题描述】:

任何人都可以帮助我如何获取带有分页的子文档列表

我只是举个例子:

{
  "accessories": [`

    {
      "data": {
        "name": "TEST",
       "updated_at": "2020-03-27T16:16:20.818Z"
      },
      "id": "56e83ea1-042e-47e0-85f8-186189c37426"
    }

  ],

  "calibration_reports": [`

    {

      "data": {
        "deleted_at": "",
        "frm27_equipment": [
          "test_cat1"
        ],
        "frm27_link": [
          "yes"
        ],
        "frm27_submit": null,
        "updated_at": "2020-03-30T10:24:52.703Z"
      },
      "id": "e4c8b1b4-7f37-46db-a49d-bca74482b968"
    },
    {
      "data": {
        "deleted_at": "",
        "frm27_equipment": [
          "test_cat1"
        ],
        "frm27_link": [
          "no"
        ],
        "frm27_submit": null,
        "updated_at": "2020-03-30T10:34:37.615Z"
      },
      "id": "445854d6-66bf-4e33-b620-05a5053119a8"
    }

  ],

    }

  ]

} 

我想在这里获得一个带有分页的 calibration_reports 列表,这可能吗?使用 couchbase(N1ql 查询) 请如果有人知道,如何使用 couchbase(N1QL) 查询获取分页结果列表的过程是什么。请帮帮我。

【问题讨论】:

    标签: couchbase n1ql


    【解决方案1】:

    解决此问题的一种可能方法是使用UNNEST

    例如:

    SELECT calreports.id
    FROM utpal u
    UNNEST u.calibration_reports calreports
    

    这将返回如下内容:

    [
      { "id": "aaa" },
      { "id": "bbb" },
      { "id": "ccc" }, 
       ... etc ...
    ]
    

    然后你可以使用普通的LIMIT/OFFSET 进行分页,如下所示:

    SELECT calreports.id
    FROM utpal u
    UNNEST u.calibration_reports calreports
    LIMIT 50
    OFFSET 150;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多