ravendbravendb-http

How to get last write date of a RavenDB collection/index


I want to detect when a collection or index was last modified or written to.

Note: This works on document level, but i need on collection/index level. How to get last write date of a RavenDB document via C#


Solution

  • RavenQueryStatistics stats;
    
    using(var session = _documentStore.OpenSession()) {
        session.Query<MyDocument>()
            .Statistics(out stats)
            .Take(0) // don't load any documents as we need only the stats
            .ToArray(); // this is needed to trigger server side query execution
    }
    
    DateTime indexTimestamp = stats.IndexTimestamp;
    string indexEtag = stats.IndexEtag;;