MongoDB, Mongoose and Node.js. Why declare a model?
I am new to document oriented databases. My question is why do I have to declare a model in MongoDB each and every time my app starts? For example:
mongoose.model('User', {
collection: 'user',
properties: [
'created',
'username',
'password',
'email'
]} //Edited: '}' was missing in original post
);
开发者_开发技巧
I want to build all tables ONCE and in my app only feed or query for data. I thought that all data architecture should be set via CLI or a special Admin (let's say PhpMyAdmin for mySql).
It turns out that in the beginning of my application each and every time I declare a data model. Doesn't make sense to me. Help :)
You need to declare a model because essentially MongoDB itself only stores collections and doesn't really bind to a schema/model. Mongoose provides a method to define a model but there are drivers which really don't even provide one (see Candy for Ruby). That's the whole point of having a document-orient database. You are not really binded to a schema and makes changes in the data structure of your database on the fly, as per requirement.
精彩评论