Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강연욱
/
myYoutube
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
2
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Flare-k
2020-05-26 21:53:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6a0f9b08acb8513561ff6a2015b9bf24d27ef564
6a0f9b08
1 parent
0d836f36
[Add] CommentDB
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletions
init.js
models/Comment.js
models/Video.js
init.js
View file @
6a0f9b0
...
...
@@ -3,6 +3,7 @@ import "./db";
import
dotenv
from
"dotenv"
;
dotenv
.
config
();
import
"./models/Video"
;
import
"./models/Comment"
;
const
PORT
=
process
.
env
.
PORT
||
80
;
...
...
models/Comment.js
View file @
6a0f9b0
import
mongoose
from
"mongoose"
;
//video 댓글에 대한 Database
const
CommentSchema
=
new
mongoose
.
Schema
({
text
:
{
type
:
String
,
required
:
"Text is required"
},
//이러한 형태를 configuration object라 한다.
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
}
/*
,
video: { //video와 comment를 연결하는 방법 #2
type: mongoose.Schema.Types.ObjectId, //그 다음 어느 model에서 온 id인지 알려줘야 한다.
ref: "Video"
}*/
});
const
model
=
mongoose
.
model
(
"Comment"
,
CommentSchema
);
export
default
model
;
\ No newline at end of file
...
...
models/Video.js
View file @
6a0f9b0
...
...
@@ -19,7 +19,12 @@ const VideoSchema = new mongoose.Schema({
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
//현재 날짜를 반환하는 function
}
},
//video와 comment를 연결하는 방법 #1
comments
:
[{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
//그 다음 어느 model에서 온 id인지 알려줘야 한다.
ref
:
"Comment"
}]
});
// 이제 이 스키마를 이용하여 model을 만들어준다.
//모델의 이름은 "Video"
...
...
Please
register
or
login
to post a comment