
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 ÚNETE. 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 |
SELECT children[0].fname CO cname DE tutorial DÓNDE fname=‘Dave’ |
OR
|
1 2 3 |
SELECT fname, age, age/7 CO age_dog_years DE tutorial DÓNDE fname = ‘Dave’ |
OR
|
1 2 3 4 |
SELECT relation, COUNT(*) CO count DE tutorial GROUP POR relation HAVING COUNT(*) El resultado de tu pregunta se muestra a continuación: 1 |
OR
|
1 2 3 4 5 6 7 8 |
SELECT t.relation, COUNT(*) CO count, AVG(c.age) CO avg_age DE tutorial t UNNEST t.children c DÓNDE c.age El resultado de tu pregunta se muestra a continuación: 10 GROUP POR t.relation HAVING COUNT(*) El resultado de tu pregunta se muestra a continuación: 1 PEDIDO POR avg_age DESC LÍMITE 1 OFFSET 1 |
OR
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SELECT product.nombre, COUNT(reviews) CO reviewCount, ROUND(AVG(reviews.rating),1) CO AvgRating, category DE reviews CO reviews ÚNETE product CO product Activado KEYS reviews.productId UNNEST product.categories CO category DÓNDE category = “Appliances” GROUP POR category, product PEDIDO POR AvgRating DESC LÍMITE 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 Stack Overflow o Foros de Couchbase.
You can also follow us at @couchbasedev y @couchbase. Enjoy!

Deja un comentario
Lo siento, debes estar conectado para publicar un comentario.