【问题标题】:Couchbase return null value after save and read document using n1ql使用 n1ql 保存和读取文档后 Couchbase 返回空值
【发布时间】:2021-01-20 05:28:31
【问题描述】:

我使用 repository.save() 在 couchbase 中插入一个文档 然后,我进行查询以查找另一个文档上的重复项。

查询是:

SELECT ARRAY_AGG(i.serialnumber) serialNumbers
FROM default tempItem
UNNEST items i
WHERE tempItem.class = "com.inventory.model.item.TempItem"
    AND META(tempItem).id = '4390dd9e-e392-4432-939f-ebf046570086'
    and i.serialnumber in (select raw serialnumber from default where class = 'com.inventory.model.item.Item'
    AND status != 'DELETED' and serialnumber is not missing)

查询的结果是:

[
  {
    "serialNumbers": [
      "9121945901",
      "9121955901",
      "9211965901"
    ]
  }
]

保存的文档如下:

[
  {
    "tempItem": {
      "class": "com.inventory.model.item.TempItem",
      "items": [
        {
          "categoryId": "67aaca7b-90b1-43e4-a6c6-0e9567bf283e",
          "clientIds": [
            "919d0ca7-c8d4-4283-8b0a-b6f2a7b39753"
          ],
          "description": "bla bla",
          "initial": 1,
          "productId": "db5c81c4-0fec-407e-8703-6f5fb69a070c",
          "serialnumber": "9121945901",
          "simType": "PREPAID",
          "status": "ACTIVE",
          "stock": 1,
          "title": "bla bla"
        }
      ]
    }
  }
]

另一个要检查的文件是:

{
  "categoryId": "67aaca7b-90b1-43e4-a6c6-0e9567bf283e",
  "class": "com.inventory.model.item.Item",
  "clientIds": [
    "919d0ca7-c8d4-4283-8b0a-b6f2a7b39753"
  ],
  "createdts": 1601801989176,
  "creator": "919d0ca7-c8d4-4283-8b0a-b6f2a7b39753",
  "description": "bla bla",
  "initial": 1,
  "prefix1": "912",
  "prefix2": "194",
  "productId": "db5c81c4-0fec-407e-8703-6f5fb69a070c",
  "serialnumber": "9121945901",
  "simType": "PREPAID",
  "status": "ACTIVE",
  "stock": 1,
  "title": "bla bla"
}

在 Spring Boot 中,当我在 seve 文档后立即运行查询时,它返回 null 结果 如果我在保存后和运行查询返回值之前让几毫秒睡眠

这是什么问题? 有人可以帮忙解决这个问题吗?

【问题讨论】:

  • 您已经知道文档密钥而不是 META(tempItem).id = '4390dd9e-e392-4432-939f-ebf046570086' 使用 FROM 默认 tempItem USE KEYS "4390dd9e-e392-4432-939f-ebf046570086"
  • @vsr 它的工作你能说和描述更多关于这个问题的内容吗?

标签: spring-boot sdk spring-data couchbase spring-data-couchbase


【解决方案1】:

这可能是因为ScanConsistency。 Couchbase 中的索引是在 asynchronously 构建的。所以如果你使用的是默认的“NOT_BOUNDED”一致性,写完之后立即用N1QL查询数据,可能还没有被索引。

我不知道如何在 Spring 中更改它,但其他选项是:

  • REQUEST_PLUS - 返回结果可能需要更长的时间,但查询引擎会确保它尽可能是最新的。
  • consistentWith(MutationState) a.k.a AT_PLUS - 为了更缩小扫描一致性,根据索引更新率,这可能会提供更快的响应。

同样,不确定 Spring,但您不必全局设置它。每个查询都可以使用不同的扫描一致性。因此,如果您重视最高性能而不是秒级精度,则可以使用默认值。如果您更看重最新的准确性而不是最高性能,则可以使用 REQUEST_PLUS 或 AT_PLUS。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多