Node.js 기초 강의 #4

라따뚜이·2021년 9월 5일
0

mongoose의 Model과 Schema가 무엇인지 알아보자.

Model : Schema를 감싸주는 역할

  • constructors compiled from Schema

Schema : Everything in Mongoose starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection.

  const blogSchema = new Schema({
    title:  String, // String is shorthand for {type: String}
    author: String,
    body:   String,
    comments: [{ body: String, date: Date }],
    date: { type: Date, default: Date.now },
    hidden: Boolean,
    meta: {
      votes: Number,
      favs:  Number
    }
  });
profile
돈만 준다면 해 노예

0개의 댓글