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.
Join the DZone community and get the full member experience.
Join For FreeArtificial 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.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments