问题描述
我有1个BlogPost模型:
const blogSchema= new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,ref: "User",},name: {
type: String,required: true,max: 50,min: 6,description: {
type: String,max: 1024,min: 25,date: {
type: Date,default: Date.now,comment: [commentSchema],});
这里的重要部分是最后一个字段评论。为此,我有另一个模式:
const commentSchema = new mongoose.Schema({
date: {
type: Date,comment: {
type: String,min: 5,userId: {
type: mongoose.Schema.Types.ObjectId,});
通常,在创建帖子时,可以添加评论。在一个单独的User.js文件中,我具有User的模型:
const userSchema = new mongoose.Schema({
name: {
type: String,unique: true,max: 255,email: {
type: String,password: {
type: String,});
我如何将它们连接在一起以一起工作。我有一个端点,所有帖子都可见(无论哪个用户提供了它们)。我希望1位用户能够对另一位用户发表评论,并在其下方显示他的名字。
关于如何创建的任何想法:
- 将评论存储在blogSchema的评论字段中的端点
- 用户将被记录在commentSchema 中
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)