Login | Register  
View Article

Current Articles | Categories | Search | Syndication

Loading game data from the document database (RavenDb)

Loading custom game data from the document database is not much harder than saving it. The hardest part has been creating the indexes to retrieve documents. These indexes can be thought as stored procedures. One really nice thing about RavenDb is that it lets you check if these indexes are there, if not, then create them. Here's the code for the index that I'm currently using: 

/// <summary>

/// Creates the needed indexes, if they don't exist.

/// </summary>

public static void CreateIndexes()

{

    var store = Instance;

 

    store.DatabaseCommands.PutIndex(

        "GetPlayerByDatabaseId",

        new IndexDefinitionBuilder<PlayerDocument>

        {

            Map = docs => from doc in docs

                          select new

                          {

                              doc.DatabaseId

                          }

        });

}

That DatabaseId is to match the document being saved to the player's settings in the database. It keeps things tidy.

posted @ Tuesday, May 24, 2011 12:24 PM by Fastalanasa

Previous Page | Next Page

COMMENTS

Only registered users may post comments.
Copyright 2007-2012 by WheelMUD  | Terms Of Use | Privacy Statement
Google Analytics Alternative