RavenDB is quite powerful in terms of what you can do with it. It has amazing data storage and replication capabilities that come in handy when you are dealing with a huge data set. Today, we are going to take a look at how you can documents in a RavenDB database in order to get the optimum performance from your database. This way, you will be able to handle user request in an efficient and reliable manner with little or no need for maintenance.
For one, most people make the error of modeling their data as they would on a typical relational database. Raven is non-relational and using a relational model will not give you the results you desire. Being documented oriented in nature, raven can give you some amazing results when you stick to its nature. There are a number of things that you need to keep in mind when approaching the document oriented nature of raven.
1. RavenDB Documents are not flat
In a raven database, you are not limited to a row like in a relational database. You can store more than just keys and values in your raven database and this can even include complex object graphs. Since you do not need a relation in order to store complex data structures in a raven database, there is little work involved in storing your data. This is due to the fact that we do not need different tables in order to store various data elements in a database. A single document can be used to store as much data as we need in the format we want. This way, we only need a single request to get all the data we need instead of having to look at relations and what not if we were using a relational database. This brings us to the next point.
2. RavenDB is not relational
Using relational concepts in Raven is a mistake most people often make. There is a reason why RavenDB is not relational. For one, it makes it easy to optimize storage and management of documents. You also get to store huge amounts of data which most database have nowadays. With the non-relational nature of RavenDB, each document is treated separately and independently meaning it can be stored anywhere in the system.
With RavenDB, every document is expected to make full sense on its own and you are encouraged to put all the information you require into a single document. Having all the necessary details in a single document enables you to maximize usage of the RavenDB architecture for your data storage purposes and you are able to get more out of your database.
3. Entities and Aggregates
This is something that you need to know in order to fully grasp the document oriented nature of the raven database. Aggregates have several entities and value types controlling access to all the objects that fall within its boundaries. This means that external reference will only refer to the aggregate root and not to the child objects. In RavenDB, the aggregate root is a document. This means that there will be no expensive computation needed in order to go through the aggregate to get to the object we need.
4. Associations Management
RavenDB also makes it easy to have association management by making use of the associated document key and loading the association with the related document when it is needed. This makes it easy to have a huge dataset and still maintain associations between different documents.