RavenDB and multiple databases

In my previous two posts about RavenDB I used a Book class as the example. The first example was an ASP.NET MVC 3 application and the second was an ASP.NET MVC 4 application and I just copies the Books class from the first to the second example. As I just used the default namespace in both projects .NET would consider this two different classes, after all the namespace and assemblies are different.


How does RavenDB handle CLR types

It turns out RavenDB doesn’t really care about these differences with namespaces and assemblies. The extra information is stored as metadata along with the book data but only the actual class name, Book in this case, is used as the type discriminator. The screenshot below shows the metadata of one of the books I created using the original MVC3 application.


However when I started the second MVC4 application all 5 of the previously created books just appeared, even though the Book class in that application used a different namespace. And I could edit and save them without any problems. This did change the metadata to display the new namespace as shown in the screenshot below.



The important thing to remember here is that RavenDB just cares about our class name and will just use the data. In this case not much of a problem but that will not always be the case.


Using multiple database

The solution is the same as with SQL Server, just create multiple database to separate data from different application. Now you can go into the RavenDB management studio and create a new database there.


That works just fine But you can do it even easier. Just specify the database name in the connection string. In that case RavenDB automatically used that database for all operations and if it doesn’t exist yet it will be created as needed.

   1: <connectionStrings>

   2:   <add name="ravenDB"

   3:        connectionString="Url=http://localhost:8080;Database=Mvc4Demo"/>

   4: </connectionStrings>

Using unique databases for your applications you can be certain that you don’t inadvertently start mixing data from different applications just because the class name is the same.

Deleting old databases

One none obvious thing is how to delete old databases you don’t need any longer. There is no delete database option or command in RavenDB. In the screenshot below I have a database called OldData.
In order to delete it I have to go the default database and find the document pointing to this database and delete this.

Once that is done I can locate the actual folder on disk and delete it.




Leave a Reply

Your email address will not be published. Required fields are marked *