Joins

N1QL does contain support to perform joins on documents with a caveat—the joins must be made across different buckets. While this is a limitation for several use cases, it does provide a means of putting data together from disparate document sources.

Since this chapter focuses on the beer-sample database, the following join next imagines a setup where beer and brewery documents are stored in two separate buckets named beers and breweries, respectively:

SELECT *
FROM beers AS b
JOIN breweries AS b2
KEYS b.brewery_id

Get Couchbase Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.