Hello,
I am new to Couchbase N1QL and querying an array doesn’t work like I expect. The example document:
{
“type”: “product”,
“sku”: “B2B_SUBSCRIPTION”,
“items”: [
{
“status”: “Active”,
“name”: “B2B Services v1”,
“OrderItem__type”: “SUBSCRIPTION”,
“test”: 1
},
{
“status”: “Active”,
“name”: “B2B Unlimited v1”,
“OrderItem__type”: “UNLIMITED”,
“test”: 2
}
]
}
I want only the item that matches the WHERE condition, but all three of these queries return both items. Can somebody explain what I am doing wrong? (I tried with both == and = .)
SELECT t.items FROM test t UNNEST t.items p WHERE p.OrderItem__type==“SUBSCRIPTION”
SELECT t.items
FROM test t
WHERE ANY item IN t.items SATISFIES
item.OrderItem__type == "SUBSCRIPTION"
END
SELECT t.items
FROM test t UNNEST t.items i
WHERE i.OrderItem__type != “SUBSCRIPTION”