Over a million developers have joined DZone.

Artificial Documents in RavenDB 4.0

DZone's Guide to

Artificial Documents in RavenDB 4.0

In this post, we take a look at a new feature of RavenDB 4.0, namely artificial documents, and how they can help with indexing and MapReduce operations.

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

Artificial documents are a really interesting feature. They allow you to define an index and specify that the result of the index will be… documents, as well.

Let's consider the following index, running on the Northwind dataset.


We can ask RavenDB to output the result of this index to a collection in addition to the normal indexing. This is done in the following manner:


And you can see the result here:


The questions here are, what is the point? Don’t we already have the exact same data indexed and available as a result of the MapReduce index? Why store it twice?

The answer is quite simple. With the output of the index going into documents, we can now define additional indexes on top of them, which gives us the option to very easily create recursive MapReduce operations. So you can do daily/monthly/yearly summaries very cheaply. We can also apply all the usual operations on documents (subscriptions and ETL processes come to mind immediately). That give you a lot of power, and without incurring a high complexity overhead.

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 ,artificial documents ,mapreduce

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}