Ayende @ Rahien

It's a girl

Porting MVC Music Store to Raven: Advanced Migrations

I noticed that I had  typo when I inserted the albums data, the artist data was stored as “Arist”. This give me a chance to show you how we can do a migration that is a bit more advanced.

using (var documentStore = new DocumentStore { Url = "http://localhost:8080" })

    var count = 0;

        var queryResult = documentStore.DatabaseCommands.Query("Raven/DocumentsByEntityName", new IndexQuery
            Query = "Tag:`Albums`",
            PageSize = 128,
            Start = count

        if (queryResult.Results.Length == 0)

        count += queryResult.Results.Length;
        var cmds = new List<ICommandData>();
        foreach (var result in queryResult.Results)
            var arist = result.Value<JObject>("Arist");
            if(arist == null)
            result["Artist"] = arist;

            cmds.Add(new PutCommandData
                Document = result,
                Metadata = result.Value<JObject>("@metadata"),
                Key = result.Value<JObject>("@metadata").Value<string>("@id"),


    } while (true);

The code itself should be hard to follow I think, it shows how we can manipulate documents by working with the JSON document directly, instead of having to go through an object layer.


Posted By: Ayende Rahien

Published at

Originally posted at


05/25/2010 01:41 AM by

"The code itself should be hard to follow"

Should or Shouldn't?

Code makes sense.

Frank Quednau
05/25/2010 09:42 AM by
Frank Quednau

I think it isn't very hard to follow, if you want it to, you should try a bit harder. This is the second time you're using a "while true...do" pattern. Is this because of the asynchronous nature of setting up the index? If that's the case, it could be helpful to have some high-level construct for situations like that that blocks until the desired effect is in place.

Comments have been closed on this topic.