Range queries

We've seen the basics of key range queries but haven't fully explored how they work. Understanding range queries is critical in order to understand how to perform a number of common query tasks. We'll start by revisiting a basic range query. We'll use a simple document structure, as shown here:

{
  "firstName": "Hank",
  "lastName": "Moody",
  "type": "user"
},
{
  "firstName": "Karen",
  "lastName": "Van Der Beek",
  "type": "user"
},
{
  "firstName": "Becca",
  "lastName": "Moody-Smith",
  "type": "user"
}

In this example, we have three documents. We'll start by writing the map function, which will allow us to perform queries by last name. This is our standard view definition with a check on type and for the existence of a lastName property:

function ...

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.