这些都是我的两个原理图进行讨论和回复:Mongoose和node.js,填充并保存在数据库中?
Source code for the two schematics
const mongoose = require('mongoose');
const ObjectID = mongoose.Schema.Types.ObjectId;
let discussionSchema = mongoose.Schema({
title: {type: String, required: true},
content: {type: String},
author: {type: ObjectID, required: true, ref: 'User'},
date: {type: Date, default: Date.now()},
reply: [{ type: ObjectID, ref: 'Replying' }]
});
let discussionReplyingSchema = mongoose.Schema({
content: {type: String, required: true},
author: {type: mongoose.Schema.Types.ObjectId, required: true, ref: 'User'},
date: {type: Date, default: Date.now()}
});
const Discussion = mongoose.model('Discussion', discussionSchema);
const Replying = mongoose.model('Replying', discussionReplyingSchema);
module.exports = Discussion;
module.exports = Replying;
这是在我的控制器:
Source code for the controller
replyPost: (req, res) => {
console.log(req.body);
let id = req.params.id;
let replyContent = req.body.replyContent;
console.log(replyContent);
}
我试图让登录用户和他的回复(作为字符串),并将其保存在猫鼬数据库中,以便我可以在当前显示它讨论。
这就是数据库是如何现在:
“答复”:[],
任何想法如何,我可以做到这一点?
如果您将代码放入问题中,而不是链接到图像,它将会更有用。 – Michael
我对此造成的不便表示抱歉,Michael在这里是原理图:编辑:其实我不能说它太长,对不起。 – shefasf
你可以编辑问题并添加代码吗? – Michael