如何 select 使用 N1ql 查询文档的子字段

How to select a sub-fields of a document using N1ql query

我可以 Select 使用 N1ql 查询的特定字段的子元素吗???

示例:

{
  "content": {
    "_id": "88w73c9e-f7ed-4816-7778-5247e69cd77450",
    "_type": "Publish",
    "author": "abcd",
    "book": {
      "$ref": "03ee49ec-4452-4ebs-9f49-9f3aa4rra53f",
      "_type": "Book"
    }
  }
}

从子对象到 select 字段的命令使用点表示法。

例如,从 test 存储桶中的所有文档中获取字段:

SELECT content.book.`$ref`, content.book._type FROM test;
  • SELECT content.book.`$ref`, content.book._type:这些是 select 从 test 存储桶中的所有文档编辑的字段。
    • `$ref` 在反引号中,因为美元是保留字符。
  • FROM test:这是将执行的存储桶查询。

查询将return以下信息:

[
  {
    "$ref": "03ee49ec-4452-4ebs-9f49-9f3aa4rra53f",
    "_type": "Book"
  }
]

要根据文档的内容进行查询,则可以使用以下查询:

SELECT content.book.`$ref`, content.book._type FROM test WHERE content. author = "abcd";

有关 N1QL 的详细信息,请参阅 Couchbase documentation and N1QL tutorial