Book Image

Couchbase Essentials

Book Image

Couchbase Essentials

Overview of this book

Table of Contents (15 chapters)
Couchbase Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Simple queries


N1QL queries are likely to feel somewhat familiar to you as the language is very much like SQL and other such query languages. To illustrate just how similar N1QL and SQL are, consider the following query:

SELECT *
FROM beer-sample

This basic N1QL query looks and feels like the equivalent SQL query, and it does what you would expect it to do—it retrieves all documents from the beer-sample bucket. Recall that documents in a Couchbase bucket are not contained in a second-level namespace. As such, there is no equivalent of a SELECT * FROM Table statement.

Instead, if you want to find all brewery documents, you can write a N1QL query similar to the map function you would write in the case of a view. In both the cases, you have to check the convention-based type property to identify a document's taxonomy:

SELECT *
FROM beer-sample
WHERE type == "brewery"

Similarly, we can apply an additional WHERE clause to filter the results by another property before they are returned, as follows...