Database schema is nothing but a table. Database model is a class that encapsulates a certain database schema like a class, so that programmers can invoke method on it to manipulate that database. Imagine creating a database schema called 'User', that has fields relevant to User. How would you do it?
const mongoose = require('mongoose')
// creates a table with name, email, password column
const userSchema = mongoose.schema({
name: String
email: String
password: String
})
// create a database model of userSchema, and call that model 'User'.
const User = mongoose.model('User', userSchema);
module.exports = { User }
Very easy!
Continue to the next article to find more about how to create a data object through POST request
'Archive until 15 Jul 2021 > Node + React + Mongo' 카테고리의 다른 글
Understanding the backend of Fullstack Part 4 (0) | 2021.07.13 |
---|---|
deploying frontend (react) and backend (express/node) (0) | 2021.05.09 |
[Heroku Deployment] (0) | 2021.05.08 |