1

I own a small chat based game that allows you to own items, trade them with other people, and use them for various things.

Currently, I have a JSON file storing all the data related to each individual item, like the damage, accuracy, name, description, and then this data is all parsed into constant fields the on startup of my application.

Now to store the actual inventory of the player, I use a MongoDB database, which has a dictionary of the item name, acting as a key, and a integer, acting as the quantity of that item that they own. So that way whenever the item information is needed, it simply gets fetched from the constant data using the key.

The problem is I want to be able to add more user specific things which are variable for each individual item, like degradability, damage increases and other things.

How would I go about handling this? I would also like to know if the way I am currently doing things is on the right track.

1
  • Oh, that's an interesting design question. But too broad for this site, I'm afraid. :) Commented Jun 20, 2017 at 12:44

1 Answer 1

1

Your basic model (items held separately, references stored with the player) is very much from the relational world. This works with mongo only insofar, as your number of distinct items is small enough to hold them in memory, so that you do not have to do multiple database roundtrips or table joins to collect all the data for a player.

When you transition from item "templates" to item "instances", probably this will not work any more, as the number of items grows too large.

I guess, that the normal query will be something along the lines of "read a player and all his items". Then, you should really store the items along with the player in all their details (json array with concrete objects.) In mongo this is a single read call for one player document and thus very fast.

Thus:

  • keep the items collection as you have it to hold templates to create new items
  • put individual copies of items into an array on the player document

(This advice is only to be taken seriously if a player with his items does not exceed the document size limit of 16 mb.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.