Reputation: 17999
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.
Upvotes: 1
Views: 132
Reputation: 932
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'}
});
Upvotes: 2