Web/Node.js

mongoose schema

mongoose schema?

mongoDB는 NoSQL이기 때문에 schema 없이 데이터를 유연하게 관리할 수 있는 장점이 있지만, 상용 서비스 운영 시 데이터의 일관성 및 중복성의 문제가 발생할 수 있다. 이럴 때 스키마를 사용한다.

 

/* ./model/post.js */

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const postSchema = new Schema({
    title : String,
    content: String,
    create_date : {type: Date, default: new Date()},
})

// 이로써 외부 파일을 통해 스키마를 적용할 수 있음
module.exports = mongoose.model("post", postSchema);

'Web > Node.js' 카테고리의 다른 글

mongoose  (0) 2022.01.10
express-session  (0) 2022.01.04
미들웨어  (0) 2022.01.04
express - HTTP method  (0) 2022.01.04
Routing  (0) 2022.01.04