如何解决猫鼬评论和回复模式
我正在关注此链接,以了解如何为带有评论和回复的社交媒体类型模块设计架构。 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,Shared_Post: String,Shared_Newmessage: String,Shared_PostDetails: [{type: Schema.Types.ObjectId,ref: "socialdatas"}]
我面临的问题是答复。我的逻辑告诉我,答复应该是主注释数组中的一个数组。但是上面的鳕鱼在编译时给我一个错误。 SyntaxError:意外令牌':'
我正确地解决了吗?任何可以给我一些建议的专家。谢谢。
解决方法
我建议为comments
和players
创建一个单独的架构,然后您可以使用populate()
来访问集合之间的数据。
但是要解决上述问题,应该是这样的:
Status_Comments: [{
Comment_Number: Number,Comment_By: String,Comment_Message: String,replies: [
{Comment_By: String,Comment_Message: String}
]
}]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。