You are on page 1of 1

LQ1.

Explain Schema and Model in MONGODB in details

MongoDB is a source-available cross-platform document-oriented database program.


Classified as a NoSQL database program, MongoDB uses JSON-like documents with
optional schemas.

Schema :

A schema is fundamentally describing the data construct of a document (in MongoDB


collection). This schema defines the name of each item of data, and the type of data,
whether it is a string, number, date, Boolean, and so on.

Model :

A model is a compiled version of the schema. One instance of the model will map to
one document in the database. It is the model that handles the reading, creating,
updating, and deleting of documents. A document in a Mongoose collection is a single
instance of a model. So it makes sense that if we're going to work with our data then it
will be through the model. A single instance of a model (like a User instance in var User
= mongoose.model('User', userSchema);) maps directly to a single document in the
database. With this 1:1 relationship, it is the model that handles all document interaction
- creating, reading, saving, and deleting. This makes the model a very powerful tool.
.

You might also like