I started studied MongoDB about 2~3 days ago, and I am feeling pretty happy about it :) However.. I do have some questions.. I already did some research, and they did not clarify much.. I am developing a browser game, and all databases were in MySQL, but I decided do migrate to MongoDB. But, well, to the questions.
1) In MySQL, I used to have a map table which had the fields *map_ndx*, column, row, terrain (terrain was a foreign reference to a terrain table). Basically, each *map_ndx* indicates a different map, and row and column represent their coordinates; terrain indicates like 'woods', 'desert', categorized on the other table. Now, on MongoDB, I have a map collection which has a field *map_ndx*, and embeds several tiles. Each tile have the fields col and row, and embeds a terrain. First of all, do you think this design is efficient for a map? I will do a lot of queries searching for "tile (x,y) on map z", for instance. Second, where do I place my indexes (such as row and column)? Do I place them in the tile collection, or in the map collection (using "index 'tile.row'", for example)? I ask this because on MySQL when I queried for "select * from maps where map_ndx=1 and row=1", I would have an answer instantly. On MongoDB, if I ask for "Map.where(:map_ndx => 1).first.tiles.where(:row=>1)" it takes almost a second to complete (obs.: that syntax there is for RoR, I am operating with mongoid)
2) In MySQL, I used to have a *global_units* table, which would have the description of several units, their attacks, defenses, costs, etc. And each player would have a *user_units*, which referenced that *global_units*, and informed the quantity of units the players had for this referenced *global_unit*. Now, on MongoDB, I considered embedding the *user_units* in the user collection, which seems the ideal. However, should I keep *user_units* only referencing *global_units*, or it would be best if *global_unit* was also embedded in each player's *user_units* collection? The problem is that I would have to access the units from *global_units* on other places, such as when the player is going to build them. Therefore, even If I had them embedded on the *user_units* collection, I would also need an exclusive non-embedded *global_units* collection, so I can access their information on other places. What is the best way out here?
I know these are very specific questions, but I would be glad if someone clarified those to me! Thanks in advance, Fernando.