mostlylucid

scott galloway's personal blog...
posts - 916, comments - 758, trackbacks - 11

My Links

News

Archives

Post Categories

Misc. Coding

Handy indexes for versioning with RavenDB

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);

Print | posted on Monday, July 12, 2010 6:59 AM | Filed Under [ .NET RavenDB ]

Comments have been closed on this topic.

Powered by: