我正在做一个正在制作节点API的辅助项目。我对如何处理评论路线感到困惑,因为我也想在Story中保存评论。
这是我的模式。
comment.js
const commentSchema = new Schema({
body : {type: String, required: true},
author: {type: ObjectID, ref: 'User'}
})
story.js
const storySchema = new Schema({
//subdoc ref from user
author: {type: ObjectID, ref: 'User'},
//subdoc ref from comment
comments: [{
type: ObjectID,
ref: 'Comment'
}],
//contents of story//
title: {type: String, required: true},
body: {type: String, required: true},
date: {type: Date, default: Date.now()},
tags: [{type: String}]
})
user.js
const userSchema = new Schema({
userName: {type: String, required: true},
firstName: {type: String, required: true},
lastName: {type: String, required: true},
userEmail: {type: String, required: true},
userImg: {type: String}
})