I have document in the below structure in couchbase bucket called employees with primary key "1000"
[
{
“empName” : “ABC”
"empType”: “1”
},
{
“empName” : “DEF”
"empType”: “2”
},
{
“empName” : “GHI”
"empType”: “1”
}
]
I want to query only the employee records where empType = 1. Please help. Thanks
vsr1
2
SELECT e.*
FROM mybucket AS m USE KEYS "1000"
UNNEST d.array AS e
e.empType = "1";
Im getting an error
“msg”: “syntax error - at array”,
vsr1
4
Change array to actual array field of the document or post exact document.
Example:
INSERT INTO default VALUES ("k01", { "emp_arr": [{ "empName" : "ABC", "empType": "1" }, { "empName" : "DEF", "empType": "2" }, { "empName" : "GHI", "empType": "1" } ] });
SELECT e.* FROM default AS m USE KEYS "k01" UNNEST d.emp_arr AS e e.empType = "1";