5

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 :)

1 Answer 1

8

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.

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

1 Comment

Exactly as @neebz says. I think the important thing to remember about document-oriented databases is that its more like an "object" store. You can create arbitrary objects and have them saved in to a "collection". Which means that there are no columns defined beforehand (in an SQL sense).

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.