Complex structures

N1QL queries are not limited to simple data types such as strings and numbers. With N1QL, you are able to operate on JSON objects and arrays as you could with map functions written in JavaScript.

As a simple example of a nested object, consider the brewery documents in the beer-sample bucket. These documents have geo data contained in a nested object with the geo property:

{
  "type": "brewery",
  "geo": { 
    "lng": -72.1234,
    "lat": 34.1234 
  }
}

The geo object contains properties for longitude and latitude. If you want to write a query to find a brewery's geo information, you can use the standard dot (.) notation, which is common with most modern object-oriented programming languages:

SELECT geo.lon, geo.lat FROM beer-sample WHERE type ...

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.