String utilities

One of the more obvious limitations of querying views is the lack of a proper LIKE operator. Though we saw in Chapter 4, Advanced Views, that it is possible to emulate a query like "starts with", it is not as robust as SQL's LIKE operator.

Fortunately, N1QL addresses this limitation with its own LIKE operator. Similar to SQL, you define a search pattern with a wildcard that is specified by a % character. In the following snippet, all breweries with Boston in their name will be returned in the results:

SELECT *
FROM brewery-sample
WHERE type = "brewery"
AND name LIKE "%Boston%"

Other string operators exist to perform standard string transformations such as SUBSTR, LOWER, UPPER, and LENGTH. You can use these functions as you do in ...

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.