ARRAY_CONTAINS (NoSQL 查詢)

適用於:NoSQL

傳回布林值,指出陣列是否包含指定的值。 您可以使用函式內的布林運算式,檢查物件的部分或完整相符專案。

語法

ARRAY_CONTAINS(<array_expr>, <expr> [, <bool_expr>])  

引數

描述
arr_expr 陣列運算式。
expr 在陣列內搜尋的運算式。
bool_expr 布林運算式,指出搜尋是否應該檢查部分比對 () true 或完整比對 () false 。 若未指定,則預設值為 false

傳回類型

傳回布林值。

範例

下列範例說明如何使用這個函式檢查陣列中的特定值或物件。

SELECT VALUE {
    containsItem: ARRAY_CONTAINS(["coats", "jackets", "sweatshirts"], "coats"),
    missingItem: ARRAY_CONTAINS(["coats", "jackets", "sweatshirts"], "hoodies"),
    containsFullMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shirts", color: "blue" }),
    missingFullMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shirts" }),
    containsPartialMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shirts" }, true),
    missingPartialMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shorts", color: "blue" }, true)
}
[
  {
    "containsItem": true,
    "missingItem": false,
    "containsFullMatchObject": true,
    "missingFullMatchObject": false,
    "containsPartialMatchObject": true,
    "missingPartialMatchObject": false
  }
]

備註