在mongodb中设计一个多媒体评论系统,是否可以在评论数组中存储不同的结构(文本结构和音频结构)

时间:2013-09-08 06:46:09

标签: node.js mongodb mongoose

我想创建一个多媒体评论系统,不仅允许用户在文本中创建评论,还可以用音频创建评论。

我打算用mongodb作为数据库,只是想设计一个像mongodb这样实现的简单结构,其中AudioComment存储音频地址,真实音频存储在GridFS中

var Content = mongoose.Schema({
    title  :  { type: String }
  , content: { type: String }
  , comments:  [TextComment / AudioComment ]

});
var TextComment = mongoose.Schema({
    name  :  { type: String }
  , date  :  { type: Date, default: Date.now }
  , text  :  String 
  , slug  :  {type:String, index:true}
});
var AudioComment = mongoose.Schema({
    name  :  { type: String }
  , date  :  { type: Date, default: Date.now }
  , audio_ref:  String 
  , slug  :  {type:String, index:true}
})

我的问题是我可以用这种方式设计架构,注释:[TextComment / AudioComment],注释数组可以接受TextComment结构还是AudioComment结构?

我以前的经历说猫鼬很难。

1 个答案:

答案 0 :(得分:0)

var Content = mongoose.Schema({
        title  :  String,
        content: String,
        comments:  {type: this.mongoose.Schema.Types.ObjectId, ref: 'AudioComment'}
...

但我不知道如何在同一领域中切换类型。 你可以使用这种语法我发现它更清楚。