Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Couchbase Essentials

You're reading from  Couchbase Essentials

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781784394493
Pages 170 pages
Edition 1st Edition
Languages

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}