Over a million developers have joined DZone.

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

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

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:


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:


Which gives:


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:


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:


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.


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.


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?


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

Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.

ravendb ,database ,query

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}