NoSQL Zone is brought to you in partnership with:

Eric is the Editorial Manager at DZone, Inc. Feel free to contact him at egenesky@dzone.com Eric has posted 804 posts at DZone. You can read more from them at their website. View Full User Profile

Why I Chose RavenDB for My Startup

03.14.2013
| 1958 views |
  • submit to reddit
In fact it was a decision which took no consideration at all: having worked with RavenDb on the inside and from the outside, it was my immediate choice. Here’s why. RavenDb stays out of the way

RavenDb is like a waiter at the best kind of restaurant. It serves your data with the minimum of fuss and gets out of the way. Unlike certain persistence technologies I could mention, there is barely any configuration involved, and not a mapping in sight. You just hand RavenDb an object or any shape or size, and RavenDb stores it. You murmur an object’s id, and RavenDb has it on your plate in an instant, child collections and all.

RavenDb is a document database. That means that you don’t need to declare a schema upfront. Whenever you hand RavenDb an object it simply serializes it to JSON format, and stores it as a blob in its persistence engine. The benefit I see from this is greatly reduced pain when deploying updates to my code, as I won’t need to worry about sql migration scripts. I can add things to my objects with impunity, and for other situations, RavenDb has very nice document patching support.

As as you’d expect, given RavenDb’s provenance, the RavenDb .Net client is awesome. It has full support for the unit-of-work pattern and transactions. Thus any entities you load within a session are tracked, and any that have changed when you save the session are sent to the database in a single transaction. Naturally, the RavenDb client has LINQ support too, with paging in queries being especially trivial to implement.

Here’s a complete snippet showing everything you need to store and retrieve objects from RavenDb.

class RavenDbDemo
{
    public void Demonstrate()
    {
        // DocumentStore is a heavy-weight object usually created once per application
        var documentStore = new DocumentStore() {Url = "http://myravendbserver.com"};
        documentStore.Initialize();
 
        // session objects are light-weight and are created per transaction
        using (var session = documentStore.OpenSession())
        {
            var person = new Person()
                {
                    Name = "Samuel Jack",
                    FavouriteDatabase = "Sql Server"
                };
 
            session.Store(person);
            session.SaveChanges();
        }
 
        using (var session = documentStore.OpenSession())
        {
            var person = session.Query<Person>()
                .First(p => p.Name == "Samuel Jack");
 
            person.FavouriteDatabase = "RavenDb";
 
            session.SaveChanges();
        }
    }
 
    public class Person
    {
        public int Id { get; set; }
 
        public string Name { get; set; }
 
        public string FavouriteDatabase { get; set; }
    }
}





 

Published at DZone with permission of its author, Eric Genesky.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)