Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

RavenDB 4.0: Raven Query Language

DZone's Guide to

RavenDB 4.0: Raven Query Language

RavenDB 4.0 has just introduced its new query language! Curious as to what it looks like and how to use it? Then come check out this post!

· Database Zone
Free Resource

Whether you work in SQL Server Management Studio or Visual Studio, Redgate tools integrate with your existing infrastructure, enabling you to align DevOps for your applications with DevOps for your SQL Server databases. Discover true Database DevOps, brought to you in partnership with Redgate.

The last big feature for RavenDB 4.0 has landed, and it is a big one. You can see the details on the PR that implemented this feature below, but you probably care a lot more about what it is.

RavenDB uses Lucene as the underlying index technology, and until now, we simply exposed (slightly modified) Lucene syntax to our clients. That was easy to do and quite effective, but it also meant that we were limited to somewhat arcane query language and what it could do.

In RavenDB 4.0, we now have a full query language, and you can see how this looks like below:

image

This will produce the results that you expect, giving you all the companies residing in London in the database.

The rest of the system behaves just the same; this query is going to hit the query optimizer, an index will be created if one does not already exist, etc. It is just that our query language is both much nicer to look at and allows us to work with it in a much more structured manner (and yes, that is a pun).

We also support aggregation:

image

Which gives:

image

This is automatically creating a map/reduce index and does all the work for you. We also have support for querying on indexes directly via:

image

If you are familiar with how we used to have to do range queries, you can see how big an improvement this is. This is actually a pretty significant feature because you can define a static index to do whatever you want with the data, and then query on top of that.

You can also do the usual full-text operations directly in the query language:

image

We decide to go with the method abstraction for most operations because it allows us a lot of freedom in the syntax and gives very readable queries.

Here is an example of us trying a more complex query. In this one, I want to find companies in London, the U.K., or France. But instead of just wanting to find them in that particular order, I want to get them with ranking.

image

I really want a company in London, so that should sort first, and then U.K.-based companies and finally France companies. You can see the results of the query below. This query also shows how we can do projections in a much nicer way.

image

The feature just landed in the main branch and we are now working through all of the rough edges, but it is very exciting since it gives you a natural way to query RavenDB without losing any of the power.

I mentioned that this was a big change, right?

image

And that is just for the C# work; we still have to update the other clients.

It’s easier than you think to extend DevOps practices to SQL Server with Redgate tools. Discover how to introduce true Database DevOps, brought to you in partnership with Redgate

Topics:
ravendb ,database ,query

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}