TIL040_210516

JIYOON·2021년 5월 18일
0

TIL

목록 보기
40/42
post-thumbnail

🍊 감상

공부 방식을 바꾸기로 했다.
걍의를 무작정 듣는 것보다 출력이 중요하다.
강의를 들으면서 기록하지 않고 강의를 끝까지 들은 후 강의의 내용을 기억해내서 적어보기

📙 코딩 2시간 + 인적성 수리+추리 영역 8시간
👍🏼 -
👎🏼 -

🚀 목표

  • Udemy : The web developer bootcamp 2021 강좌 수강 (501/682)
  • Udemy : Javascript algorithms and data structures 강좌 수강 (11/249)
  • 개인 프로젝트 진행
  • 라이징프로그래머 3 합격!
  • SSAFY 6기 SW 적성진단 준비

The Web Developer Bootcamp 2021

45: Mongo Relationships With Express

455. Defining Our Farm & Product Models

//in product.js
//스키마는 name, price, category
//farm과 연결할 것
const mongoose = require('mongoose');
const { Schema } = mongoose.Schema;

const productSchema = new Schema({
  name: {
    type: String,
    required: true,
  },
  price: {
    type: Number,
    required: true,
    min: 0,
  },
  category: {
    type: String,
    lowercase: true,
    enum: ['fruit', 'vegetable', 'dairy'],
  },
  farm: {
    type: Schema.Types.ObjectId,
    ref: 'Farm',
  },
});

const Product = mongoose.model('Product', productSchema);

module.exports = Product;

//in farm.js
//스키마는 name, city, email - name과 city는 required 아니면 메시지 나오게
//product와 연결할 것

const mongoose = require('mongoose');
const { Schema } = mongoose.Schema;

const farmSchema = new Schema({
  name: {
    type: String,
    required: [true, 'Farm must have a name'],
  },
  city: {
    type: String,
  },
  email: {
    type: String,
    required: [true, 'Email required'],
  },
  product: {
    type: Schema.Types.ObjectId,
    ref: 'Product',
  },
});

const Farm = new mongoose.model('Farm', farmSchema);

module.exports = Farm;

457. Creating New Farms

//in product.js
//스키마는 name, price, category
//farm과 연결할 것
const mongoose = require('mongoose');
const { Schema } = mongoose.Schema;

const productSchema = new Schema({
  name: {
    type: String,
    required: true,
  },
  price: {
    type: Number,
    required: true,
    min: 0,
  },
  category: {
    type: String,
    lowercase: true,
    enum: ['fruit', 'vegetable', 'dairy'],
  },
  farm: {
    type: Schema.Types.ObjectId,
    ref: 'Farm',
  },
});

const Product = mongoose.model('Product', productSchema);

module.exports = Product;

//in farm.js
//스키마는 name, city, email - name과 city는 required 아니면 메시지 나오게
//product와 연결할 것

const mongoose = require('mongoose');
const { Schema } = mongoose.Schema;

const farmSchema = new Schema({
  name: {
    type: String,
    required: [true, 'Farm must have a name'],
  },
  city: {
    type: String,
  },
  email: {
    type: String,
    required: [true, 'Email required'],
  },
  product: {
    type: Schema.Types.ObjectId,
    ref: 'Product',
  },
});

const Farm = new mongoose.model('Farm', farmSchema);

module.exports = Farm;

0개의 댓글

관련 채용 정보