Search code examples
ravendbravendb-studio

How to get last write date of a RavenDB document via C#


In the Raven Studio UI, when you look into a document you can read (on the right of the page) the last write date of the document.

I don't find any access via the client API in C# to this information. Do you know if it's possible ?


Solution

  • The last modifed date is stored in the metadata of the document. You can access it like this:

    var product = session.Load<Product>(1);
    RavenJObject metadata = session.Advanced.GetMetadataFor(product);
    
    // Get the last modified time stamp, which is known to be of type DateTime
    DateTime lastModified = metadata.Value<DateTime>("Last-Modified");
    

    See Working with document metadata for more information about RavenDB's metadata.