I am new to Couchbase and have been trying this for several hours. Have looked through the documentation but haven’t been able to locate this specific scenario, My bucket has documents:
{
"type":"order",
"order_id":"1",
"products":[{"product_id":"1","qty":10},{"product_id":"2","qty":20}]
},
{
"type":"product",
"id":"1",
"name":"Product one"
},
{
"type":"product",
"id":"2",
"name":"Product two"
}
The product_ids in the “order” type document map to the id field in the “product” type document. I just need to enhance the order document and get the result as below:
{
"type":"product",
"id":"2",
"name":"Product two"
}
I have tried:
select orderview.order_id,ARRAY{"product_id":l.product_id,"qty":l.qty,"name":m.name} for l in orderview.products end as product_view
from `Orders` orderview inner join `Orders` m on orderview.product_id=m.id
where orderview.type="order" and m.type="product";
This returns no results.
What N1QL should I use?