Hey there, I'm diving into the world of Meteor and Mongo and I've got some basic questions on designing databases.
Imagine I'm creating a turn-based strategy game similar to Advance Wars. I'm stuck on how to structure my data efficiently.
I put together a little demo in my html:
{{#each chars}}
<div class='char' style={{get_style}}>
...
</div>
{{/each}}
For this, I have a helper set up on Template.body:
Template.body.helpers({
chars: function() {
return Characters.find({});
},
...
})
Now, everything seems fine when running just one game. But handling multiple games concurrently is where I hit a roadblock.
One solution could involve having a Games collection wherein each Game links two or more Players, each with their own list of Characters. Each Character would then hold an x and y position. But I'm unsure about querying after replacing Characters.find({})
.
Possibly something like
Game.findOne({game_id: game_id}).players[player_id].characters
could work. However, I'm not clear on the performance implications. Will Meteor fetch the entire game object every time a character moves?
Another option that requires minimal changes might be
Characters.find({game_id: 123, player_id: 1})
. This way, all Characters from all games are stored in one large collection. Though it feels odd not encapsulating Characters under a specific Game, maybe this approach is more practical.
After jotting down those thoughts, the second option seems more logical. I'd probably define other internal game objects as separate collections. Does this sound like a good plan to tackle this issue?