Page 370 - Nodejs 교과서 개정2판
P. 370
comment: String,
createdAt: {
type: Date,
default: Date.now,
},
});
module.exports = mongoose.model('User', userSchema);
ކҳझ ݽٕীࢲ Schema ࢤࢿܳ ࢎਊ೧ झః݃ܳ ٟ݅פ द௬ۄૉীࢲ ݽ؛ਸ ೞח Ѫҗ ࠺तפ
٘ܳ пп פ
ކҳझח ঌইࢲ _idܳ ӝࠄ ః۽ ࢤࢿೞ۽ _id ٘ח য ਃо হणפ աݠ ٘ झಖ݅ ੑ۱
פ
ކҳझ झః݃ীࢲ ౠೠ String Number Date Buffer Boolean Mixed ObjectId Arrayܳ чਵ۽ о
ࣻ ח ੑפ ކҊ٣࠺ ܐഋҗ ઑӘ ܰݴ ಞܳ ਤ೧ ઙܨ ࣻܳ ৈفणפ
name ٘ ܐഋ StringҊ ࣻݴ Ҋਬೠ чযঠ פ age ٘ח Number ܐഋҊ ࣻݴ
married ٘ח ࠛ ч ܐഋҊ ࣻੑפ comment ٘ח String ܐഋੑפ requiredա default ١
২࣌ ਃೞ ঋݶ рױೞѱ ܐഋ݅ ݺदೞݶ ؾפ createdAt ٘ח Date ܐഋҊ ӝࠄч D
ate.now ؘఠ ࢤࢿ द दр ੑפ
݄݃ীח ކҳझ model ݫࢲ٘۽ झః݃৬ ކҊ٣࠺ ஸ۩࣌ਸ োѾೞח ݽ؛ਸ ٟ݅פ
؆Ӗ झః݃ب ٜ݅যࠇद
schemas/comment.js
const mongoose = require('mongoose');
const { Schema } = mongoose;
const { Types: { ObjectId } } = Schema;
const commentSchema = new Schema({
commenter: {
type: ObjectId,
required: true,
ref: 'User',
},
comment: {
type: String,
required: true,
},
createdAt: {