For Programmer

15. 좋아요 싫어요 기능(1) 구조설명 - 유튜브 클론 코딩 본문

React & Node.js 프로젝트/유튜브 클론 코딩

15. 좋아요 싫어요 기능(1) 구조설명 - 유튜브 클론 코딩

유지광이 2020. 7. 27. 21:33
728x90

1.Like 와 Dislike Model을(몽고DB) 서버에 만든다.

server-models-Like.js

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

const likeSchema = mongoose.Schema(
  {
    userId: {
      type: Schema.Types.ObjectId,
      ref: "User",
    },
    commentId: {
      type: Schema.Types.ObjectId,
      ref: "Comment",
    },
    videoId: {
      type: Schema.Types.ObjectId,
      ref: "Video",
    },
  },
  { timestamps: true }
);
const Like = mongoose.model("Like", likeSchema); //1st모델의이름,2nd데이터

module.exports = Like; //다른파일에서사용가능

server-models-Dislike.js

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

const dislikeSchema = mongoose.Schema(
  {
    userId: {
      type: Schema.Types.ObjectId,
      ref: "User",
    },
    commentId: {
      type: Schema.Types.ObjectId,
      ref: "Comment",
    },
    videoId: {
      type: Schema.Types.ObjectId,
      ref: "Video",
    },
  },
  { timestamps: true }
);
const Dislike = mongoose.model("Dislike", dislikeSchema); //1st모델의이름,2nd데이터

module.exports = Dislike; //다른파일에서사용가능

해당강의

 

728x90
Comments