How to manage results from a Gamedonia Search query [Unity]

If you want to access some data sored in a collection, you will usually do a Search call to the Gamedonia servers. In general:

  • Objects are returned as type Dictionary<string, object>
  • Arrays and Lists are returned as type List<object>.
  • Simple types are returned as such.

It's important to know the structure you used to store your entities when retrieving results from the GamedoniaData API.

Let's try retrieving results from the collection movies with this entity structure:

{
    "_id": "5571889ee4b076ed059c09e7",
    "cast": {
        "main": "Marlon Brando",
        "second": "Al Pacino",
        "others": [
            "Al Pacino",
            "Robert Duvall",
            "James Caan",
            "Richard S. Castellano"
        ]
    },
    "name": "The Godfather",
    "_acl": {
        "owner": "554712fbe4b08975b74546ce",
        "mode": 0
    }
}

When obtaining this entity through a Search call, we should get the results like this:

// We query for all the movies in the collection ( "{}" query )
GamedoniaData.Search ("movies", "{}", delegate (bool success, IList list) {
    if (success) {
        // if there is at least ONE movie in the collection
        if (list != null) {

            // We pick the first movie in the list
            Dictionary<string, object> movie = (Dictionary<string, object>)list [0];

            // We pick the "cast" field of the Entity, this is a Dictionary with the fields "main", "second" and "others"
            Dictionary<string, object> cast = new Dictionary<string, object> ();
            cast = (Dictionary<string,object>)movie["cast"];

            // We print the names of the main and secondary characters of the movie, Marlon Brando and Al Pacino
            Debug.Log (cast["main"]);
            Debug.Log (cast["second"]);

            // We obtain the array with the rest of the cast (as a list)
            List<object> l = new List<object>();
            l = (List<object>)cast["others"];

            // We print the second name of the array, which is Robert Duvall
            Debug.Log (l[1]);
        }
    } else {
        //TODO Your fail processing
    }
});

More info here: Data storage guide