Hi all,
I have documents in couchbase in below format.
{
"attributes": [
"categories",
"brand"
],
"typeOfInputData": "Web page",
"weight": 100,
"type": "test"
}
I want to fetch documents where the attribute field contains the exact values.
Considering above json, how can I query to Couchbase that it would return me above document where “attributes ” array contains “categories” and “brand” (exact match) ?
vsr1
February 21, 2020, 5:50am
2
If you want order must be preserved and exact match
SELECT d.*
FROM default AS d
WHERE d.attributes = [ "categories", "brand" ];
If you want any order and array must contain both the values (attribute might have other values too)
SELECT d.*
FROM default AS d
WHERE ANY v IN d.attributes SATISFIES v = "categories" END
AND ANY v IN d.attributes SATISFIES v = "brand" END;
OR
SELECT d.*
FROM default AS d
WHERE EVERY v IN [ "categories", "brand" ] SATISFIES v IN d.attributes END;
If you want any order and exact match (no additional values in array)
SELECT d.*
FROM default AS d
WHERE EVERY v IN d.attributes SATISFIES v IN [ "categories", "brand" ] END;
Thanks a lot, that worked