猫鼬评论和回复模式

时间:2020-08-13 07:08:12

标签: mongodb mongoose mongoose-schema

我正在关注此链接,以了解如何为带有评论和回复的社交媒体类型模块设计架构。 https://www.xuchao.org/docs/mongodb/use-cases/storing-comments.html#gsc.tab=0(这是用于mongdb而非猫鼬)

我正在尝试创建这样的模式

const socialSchema = new mongoose.Schema({
    Entry_Number: Number,
    Player_Name: String,
    Player_Message : String,
    Player_Fullmessage: String,
    Player_ProfilePic : String,
    Player_UploadedPic: String,
    Player_UploadedVideos: String,
    Status_Date: String,
    Status_Feeling: String,
    Google_Profile: String,
    Status_Likes: [{Like_Number: Number, Liked_By: String}],
  Status_Comments: [
                      {Comment_Number: Number,
                       Comment_By: String,
                       Comment_Message: String},
                       replies: [
                         {Comment_By: String,
                          Comment_Message: String}
                        ],
                     ],
Friends: { type: Array, default: []},
    Shares: { type: Array, default: []},
    Shared_Post: String,
    Shared_Newmessage: String,
    Shared_PostDetails: [{type: Schema.Types.ObjectId, ref: "socialdatas"}]

我面临的问题是答复。我的逻辑告诉我,答复应该是主注释数组中的一个数组。但是上面的鳕鱼在编译时给我一个错误。 SyntaxError:意外令牌':'

我正确地解决了吗?任何可以给我一些建议的专家。谢谢。

1 个答案:

答案 0 :(得分:0)

我建议为commentsplayers创建一个单独的架构,然后您可以使用populate()来访问集合之间的数据。

但是要解决上述问题,应该是这样的:

Status_Comments: [{
                     Comment_Number: Number,
                     Comment_By: String,
                     Comment_Message: String,
                     replies: [
                        {Comment_By: String,
                         Comment_Message: String}
                        ]
                  }]