-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathComment.js
More file actions
34 lines (32 loc) · 924 Bytes
/
Comment.js
File metadata and controls
34 lines (32 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const mongoose = require("mongoose");
////USE MONGOOSE TO TALK TO MONGODB DB AND GIVE US A SCHEMA TO USE
const CommentSchema = new mongoose.Schema({
//HOW TO TAKE THE DATA FROM FORM TO PUT INTO DB
comment: {// ADD comment TO THE DB AS A STRING/SENTENCE AND ITS REQUIRED
type: String,
required: true,
},
likes: {
// ADD LIKES TO THE DB AS A NUMBER AND ITS REQUIRED
type: Number,
required: true,
},
user: {
//MONGO WILL CREATE A UNIQUE USERID
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
userName: {
type: String, unique: true },
post: {
//MONGO WILL CREATE A UNIQUE PostID
type: mongoose.Schema.Types.ObjectId,
ref: "UserName",
},
createdAt: {
////MONGO WILL CREATE A UNIQUE DATE WITH THE TIME (UTC)
type: Date,
default: Date.now,
},
});
module.exports = mongoose.model("Comment", CommentSchema);