I'm building a small product system to try and get me into Node.js, Mongo and the like. I was drawn to Mongo for the possibilities of storing products of different types in the same collection instead of having multiple tables, eav or any of the other MySQL-methods that didn't quite fit.
I was reading through tutorials and at first fell over writing a Provider for the ProductModel, but then someone suggested i should use Mongoose.
However, the issue with Mongoose seems to be that i need a set schema for each model. My first idea was that a product should have a title
and a type
attribute. Then type
would decide the overall product structure. So for example a dvd
product might have a director while a t-shirt
product would not have a director but would have different sizes.
Is it possible to implement this kind of structure in Mongoose, and how? It's my understanding that if i provide a schema for each produt type i won't be able to query them simultaneously? Does different schemas mean different collection? - I couldn't quite figure that out.
Any help and guidance is appreciated, would like to be able to use a framework instead of writing the DB handling myself (although that what was i planning to do initially, but if someone else allready did it better than me :))
Mongoose has a schemaless type which can be very useful in your case, but might not be the best solution.
ProductSchema = new Schema({any: {}});
If you change anything on this object you need to notify Mongoose about it with obj.markModified('field-name') before saving.
My suggestion is to use your own wrapper over node-mongodb-native, which I'm running on production for 7~8 months without problems.
There's another lib called mongous that you can check it out.