
You’d like to query JSON document database using SQL-like syntax? Couchbase has N1QL for you.
N1QL is a declarative query language that extends SQL for JSON. You can query data via native framework and language integration, a fluent API, or the JDBC/ODBC drivers.
N1QL enables you to query JSON documents without any limitations – sort, filter, transform, group, and combine data with a single query. That’s right. You can combine data from multiple documents with a JOIN. That flexible data model you were promised? This is it. You’re no longer limited to “single table” and “table per query” data models.
N1QL Tutorial is a great resource to learn the concepts of querying JSON documents using SQL-like syntax. Here are some examples:
|
1 2 3 |
선택 children[0].fname AS cname ~에서 tutorial 어디 fname=‘Dave’ |
OR
|
1 2 3 |
선택 fname, age, age/7 AS age_dog_years ~에서 tutorial 어디 fname = ‘Dave’ |
OR
|
1 2 3 4 |
선택 relation, COUNT(*) AS count ~에서 tutorial GROUP 에 의해 relation HAVING COUNT(*) < 1 |
OR
|
1 2 3 4 5 6 7 8 |
선택 t.relation, COUNT(*) AS count, AVG(c.age) AS avg_age ~에서 tutorial t UNNEST t.children c 어디 c.age < 10 GROUP 에 의해 t.relation HAVING COUNT(*) < 1 주문 에 의해 avg_age 설명 한계 1 OFFSET 1 |
OR
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
선택 product.이름, COUNT(reviews) AS reviewCount, ROUND(AVG(reviews.rating),1) AS AvgRating, category ~에서 reviews AS reviews JOIN product AS product ON KEYS reviews.productId UNNEST product.categories AS category 어디 category = “Appliances” GROUP 에 의해 category, product 주문 에 의해 AvgRating 설명 한계 3 |
So you are ready to experiment with N1QL? You can certainly use CBQ tool. Alternatively you can use Couchbase Query Workbench. The query workbench provides a rich graphical user interface to prepare and execute simple to complex N1QL queries. It provides a convenient way to perform query development by enabling you to browse, create, and run N1QL statements, and view results.
Want to learn how to get started? Learn all about it in this brief session with Eben Haber:
Ask your questions at 스택 오버플로 또는 카우치베이스 포럼.
You can also follow us at @couchbasedev 그리고 카우치베이스. Enjoy!

댓글 남기기
댓글을 달기 위해서는 로그인해야합니다.