RavenDB - An example of NoSQL based solution

As I promised in one of my earlier threads that I’ll try to compile an example of RavenDB and here it is . But first we need to know what an Open database is and why traditional relational databases have started acting as a bottleneck when it comes to cloud computing and horizontal growth .

*NoSQL (Wiki) : In computing, NOSQL (commonly interpreted as “not only SQL”[SUP][1]](NoSQL - Wikipedia)[/SUP]) is a broad class of database management systems identified by non-adherence to the widely used relational database management system model. NoSQL databases are not primarily built on tables, and generally do not use structured query language for data manipulation.*NoSQL database systems are often highly optimized for retrieve and append operations and often offer little functionality beyond record storage (e.g. key-value stores). The reduced run time flexibility compared to full SQL systems is compensated by significant gains in scalability and performance for certain data models.
*In short, NoSQL database management systems are useful when working with a huge quantity of data and the data’s nature does not require a relational model for the data structure. The data could be structured, but it is of minimal importance and what really matters is the ability to store and retrieve great quantities of data, and not the relationships between the elements. For example, to store millions of key-value pairs in one or a few associative arrays or to store millions of data records. This is particularly useful for statistical or real-time analyses for growing list of elements (such as Twitter posts or the Internet server logs from a big group of users).

*Here is the link to RavenDB’s website, you can read more about it here : http://ravendb.net

Let me first tell you how to set it up.

  1. First you’ll need to setup the RavenDB server. Download whole package from here (Hibernating Rhinos - Build Server).
  2. Extract it to a folder and run RavenDB-Build-888\Server\Raven.Server.exe
  3. You’ll see console screen running the server and will be showing the log. By default RavenDB runs on http port 8080, so you can access a web interface for this server at (https://dev.gupshup.org).

Now I’ll dive right in to the code, but before that lets talk about two very important interfaces.

IDocumentStore : This is the interface to main repository and its expensive to initialize it. So do it only once in your application. This is how you initialize it.
IDocumentStore DS = new DocumentStore { Url = “https://dev.gupshup.org” }.Initialize();

IDocumentSession: This creates a session to talk to your database. This is how you can use it
IDocumentSession session = DS.OpenSession()

I have a simple class that I’ll try to save in RavenDB. Here is my class

public class Student
{
public string Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}

**Add :

**public void Add(Student student)
{
using (var session = DS.OpenSession())
{
session.Store(student);
session.SaveChanges();
}
}

**Update:

**public void Update(Student student)
{
using (var session = DS.OpenSession())
{
session.Store(student);
session.SaveChanges();

        }
    }

**Delete:

**public bool Delete(Student student)
{
using (var session = DS.OpenSession())
{
session.Delete(session.Load(student.Id));
session.SaveChanges();
return true;
}
}

**Select/Search:

**public IList Select(string id)
{
using (var session = DS.OpenSession())
{
if (string.IsNullOrEmpty(id))
return session.Query().ToList();
else
return session.Query().Where(o => o.Id == id).ToList();
}
}

LINQ is official language of accessing RavenDB. They also have REST api to communicate using any non-.net consumer framework. This is pretty straightforward, for now, but in future I’ll try to add more complex examples for advance usage.

Please give it a go and come up with questions. It will push me to find answers and we all can learn this new technology that we’ll be using widely in couple of years anyways.

Re: RavenDB - An example of NoSQL based solution

I'm sure this is very informative but goes over my head. Thanks Nami.

Re: RavenDB - An example of NoSQL based solution

^ beeta tabhi kaha tha matric pass ker lo :hehe:

Re: RavenDB - An example of NoSQL based solution

Uncle degree bi lai li…lakin sciene main thi is liye yai sab meri samjh kai bahir hai. :frowning:

Re: RavenDB - An example of NoSQL based solution

NaMaan: got it. what I think, RavenDB is flat structure and no relations with other tables. basically, it deals with one huge table(unnormalized :konfused: ) but again you are sayin key value pair so its mean no duplication.

Re: RavenDB - An example of NoSQL based solution

All this sounds so interesting :(. I feel so left out.

Re: RavenDB - An example of NoSQL based solution

Yea, totally does. :chai:

Re: RavenDB - An example of NoSQL based solution

Why does SQL makes things complicated especially when it comes to coding? Havn’t done this much of SQL :bummer:

Re: RavenDB - An example of NoSQL based solution

STA its no flat at all . Well if you think RDB is two dimensional then , NoSQL is three dimensional . You can’t achieve inheritance and polymorphism with RDB , but with RavenDB you can . After like really really really long time there are some major advancements in data storage , and somehow I feel in couple of years , NoSql will all over the IT industry .

Main purpose of this topic is to prepare ourselves for future technologies , or we’ll be jobless :slight_smile:

Re: RavenDB - An example of NoSQL based solution

Learn RavenDB .NET / REST API so you won’t have to write complicated SQL queries :slight_smile: