小编Nik*_*ing的帖子

文章的猫鼬模式

我正在建立一个新闻网站,我有这个猫鼬模式:

let mongoose = require('mongoose');

let articleSchema = mongoose.Schema({
  image1:{
    type: String,
    required: true
  },
  title:{
    type: String,
    required: true
  },
  author:{
    type: String,
    required: true
  },
  date:{
    type: String,
    required: true
  },
  updated:{
    type: String,
    default: 'not updated'
  },
  title_nd:{
    type: String,
    required: false
  },
  body:{
    type: String,
    required: true
  },
  comments: [commentsSchema],
  likes:{ type:Number, default:0 }
});

let Article = module.exports = mongoose.model('Article', articleSchema);

Run Code Online (Sandbox Code Playgroud)

我想添加一个表单,以便用户可以添加他们的评论。问题是如何为评论创建新架构并将其链接到文章架构,然后如果用户添加评论,则评论添加到数据库,然后显示在文章评论部分?

mongoose mongodb node.js mongoose-schema pug

2
推荐指数
1
解决办法
710
查看次数

标签 统计

mongodb ×1

mongoose ×1

mongoose-schema ×1

node.js ×1

pug ×1