Help me choose
Archive until 15 Jul 2021/Node + React + Mongo

Set up database schema

by hajinny 2021. 1. 3.

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