Search code examples
.netnosqlravendbkey-value-store

What are the object requirements (limitations) for storing an object in RavenDB


I am researching RavenDB for use in a system (mostly as a persistant key-value cache) and need to know what are the limitations of the actual data that can be stored.

The documentation states "The only requirement is that a root entity string Id property" however all the samples and tutorials I am seeing only store simple string, int, decimal, bool data types.

Is it possible to store this object?

public class StorableObject {
   public string Id {get;set;}
   public object ValueObject {get;set;}
}

Using this (sudo) code?

// I just copy and pasted this from a random blog post -- an example to show a complex object with a lot of hierarchy, methods, properties, etc.
string boundary = Guid.NewGuid().ToString();
HttpWebRequest request = HttpWebRequest.Create("http://twitpic.com/api/uploadAndPost")
    as HttpWebRequest;
request.Method = "POST";
request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
request.PreAuthenticate = true;

var objectToStore = new StorableObject { ValueObject = request }; 
session.Store(objectToStore);
session.SaveChanges();

And get it back out like this:

var storedObject = session.Load<StorableObject>("objects/123456789");
var request = (HttpWebRequest) storedObject.ValueObject;

Thanks for your feedback, please excuse my contrived example, it was the easiest way I could describe what I am trying to do without delving into a bunch of domain knowledge/models.

Kyle


Solution

  • All objects in Raven are stored as JSON and are serialised using Json.NET. So as long as that can serialise your type it'll work.