Search code examples
couchbasesql++

Couchbase cant see my query fields/rows when using NEST


I want to see my reviews but it does not show it only the product fields/rows

https://query-tutorial.couchbase.com/tutorial/#14

I combine the product and reviews collections together:

SELECT 
p.*, r.*
FROM product AS p
 LEFT NEST reviews AS r
  ON (META(r).id in p.reviewList) WHERE META(p).id = 'product320';

if I use SELECT * then it works but I have to calculate the avg so I have to use this:

SELECT
p.*, r.type, avg(r.rating) ....

Solution

  • NEST makes r as ARRAY

    SELECT 
    p.*,  ARRAY_AVG(r[*].rating) AS avg_ratings
    FROM product AS p
    LEFT NEST reviews AS r
      ON (META(r).id in p.reviewList) WHERE META(p).id = 'product320';