JOIN 5 documents with 1 foreign key

n1ql

#1

Hi,

How to join 5 documents using 1 foreign key?

Example:

document 1 : { “id”: “master_controller”, “type”: “masterData”, etc…}
document 2: {“id”: “sample1”, “masterId”: “master_controller”, etc…}
document 3: {“id”: “sample2”, “masterId”: “master_controller”, etc…}
document 4: {“id”: “sample3”, “masterId”: “master_controller”, etc…}
document 5: {“id”: “sample4”, “masterId”: “master_controller”, etc…}

I want to join those 5 documents in 1 query using the field masterId

We are currently using coubhase server 5.0

Any help will be appreciated, thank you!


#2
SELECT  ARRAY_AGG(d) AS docs, d1
FROM default AS d
JOIN default AS d1
ON KEYS d.masterId
WHERE ......
GROUP BY d1;

#3

Does this query joins 2 documents? (masterdocument to any document that contains masterId)

I need something that will combine those 5 given document samples using the 1 id as reference for the 5 documents


#4

Lookup Join. From other documents to Join master

SELECT d.*, d1.* 
FROM default AS d JOIN default AS d1 ON KEYS d.masterId 
WHERE ...... ;

Index JOIN , From master document other documents.

SELECT d.*, d1.* 
    FROM default AS d JOIN default AS d1 ON KEY d1.masterId FOR d
    WHERE ...... ;

Pre 5.50

In 5.50 ANSI JOINS