Mainly for me to remember this but if you're using the excellent Versioning bundle for RavenDB then you'll find you quickly need to work out a way to get the latest version of a document if querying on any field other than ID (I *believe* ID actually only gets the latest one). The little index definitions below do just that (the secome one is just adding another field to the map so I can query by that...useful example)...
documentStore.DatabaseCommands.PutIndex("CurrentVersion",
new IndexDefinition
{
Map = @"from doc in docs
where
doc[""@metadata""][
""Raven-Document-Revision-Status""] !=
null &&
doc[""@metadata""][
""Raven-Document-Revision-Status""] ==
""Current""
select new {doc};"
},true);
documentStore.DatabaseCommands.PutIndex("CurrentImageVersionBySlug",
new IndexDefinition
{
Map = @"from doc in docs
where
doc[""@metadata""][""Raven-Entity-Name""] ==""Images""
&& doc[""Slug""]!=null &&
doc[""@metadata""][
""Raven-Document-Revision-Status""] !=
null &&
doc[""@metadata""][
""Raven-Document-Revision-Status""] ==
""Current""
select new {Slug=doc[""Slug""]};"
, } , true);