Hey everyone, so I’m learning MongoDB to build the structure to my game and as I get closer to completing M320 - Data Modeling (MongoDB University) I’ve built the first version of my data structure. I was wondering if the community could give their opinion.
This is a very simple structure used to represent items owned by a player in a game. I wanted a way to make it so that there was never any stale data and that any items that are updated are immediately reflected in future queries.
So I came up with a structure where there is three collections with different types of documents.
The Item Prototype which contains static information about an item. Things like name, description, type, requirements and so on. These are things that are going to be read often, but written very rarely.
The Item is basically an instance of the Item Prototype this is an item that actually exists in the game. It contains some data specific to the item such as who owns it, who’s created it, the durability, etc.
The Character is nearly irrelevant here, but needed as the parent to the Item.
So here I will layout my structure…
Item Prototype – Formatted Code Link
{
_id: ObjectId("..."),
name: "Rusty Shortsword",
type: "weapon",
subtype: "sword",
description: "It looks like it hasn't been used in awhile.",
stackable: false,
maximum_carry_limit: 2147483647, // int32 max safe value
merchant_value: 0,
requirements: {
{ k: "strength", v: 3 },
{ k: "quest", v: 17 }
},
modifiers: {
{ k: "accuracy", v: 1 }
}
}
Item – Formatted Code Link
{
_id: ObjectId("..."),
item_id: ObjectId("..."), // Item Prototype _id
owned_by: ObjectId("..."), // Character _id
durability: 100.0,
created_by: ObjectId("..."), // Character _id
created_at: new Date()
}
Character – Formatted Code Link
{
_id: ObjectId("..."),
...
}
Item Prototype → Item will be a One-to-Zillions setup, where Item → Character will be a many-to-one.