1

I planned to use MongoDB NoSQL database for a video game, but I'm wondering about some things that I don't understand really clearly and I didn't find answer about them so far.

I understood that it was possible to store a document instance (a car for example) into another document instance (a user), but how does that works? Because if it's a copy by value, if I update my car, the user will have a car that is not up-to-date! So I guess it's a copy by reference. Or maybe it's not a copy but directely some kind of weird link such as we used to do with SGBD databases with the ID field.

But, another thing, if I update my schemas (and I will for sure), the new fields or the OLD fields that previously existed won't be updated in the existing data... It looks like it's a know problem and there is some solution, do you have any good links that explain how deal with that? I'm just thinking here, my DB is not wrote and I want to make the best choices about the design. I never used NoSQL stuff before and I'm trying to design it but I still have a lot of misunderstood and "bad" pratice from SGBD DB.

By the way, MongoDb is a security hole (no password by default, etc.), do you have links to protect a database with mongoDb? Thanks.

3

1 Answer 1

2

I am just learning Mongo myself, but I hope I can provide some help. Note the concept of Mongo being a schema-less database, which means that one User may have a car, another have no car, and others have a different car. So, if you want to update the car definition, you need to modify existing user documents accordingly. There is no central definition for the car - i.e. no relationship to a central car table like in an RDBMS.

You can add some structure to Mongo using Mongoose Schemas. This allows some flexibility for changes of schema, for example you can add new properties and apply a default value, meaning you don't need to update existing documents. i.e.:

BEFORE

var Book = new Mongoose.Schema({
  title: {type: String}
});

AFTER

var Book = new Mongoose.Schema({
  title: String
  category: {type: String, default: 'fiction'}
});
Sign up to request clarification or add additional context in comments.

2 Comments

I actually use mongo since few months now, but only on one table, so I know some things about it but I was wondering, few months ago, about the "central definition", because I couldn't really imaigne a database without central definitions, but it was not so important at the time and I worked on something different. I use also mongoose. But now... I don't know if it's acceptable for a video game to accept the fact that some central datas could be duplicate in another documents without be linked between them. And I'm wondering if it could be better for some to deal with the ID and not a copy.
Yes the fully denormalized approach is challenging to understand having worked with RDBMS' for so long!

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.