我正在使用社交网站之类的instagram。在这里,我建立了用户和帖子模型之间的一对多关系,即帖子的ID被保存在其用户(作者)个人资料中,并且帖子模型中的作者详细信息被硬编码。这里的问题是,当用户编辑他/她的个人资料时,在该用户的个人资料更新之前发布的帖子中,该更改就不会发生。
//Post model
const postSchema = new Schema({
category : {
type: String
},
content: {
type: String
},
caption: {
type: String
},
tags: [{
type: String
}],
createdAt: {
type: Number,
required: true
},
author: {
uid: {
type: String,
required: true
},
name: {
type: String,
required: true
}
} ,
likes:[{
type:String
}],
comments:[{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}]
});
//user model
const userSchema = new mongoose.Schema({
_id: {
type: String,
required: true
},
name:{
type: String,
required: true
},
avatar:{
type:String
},
bio:{
type: String
},
followers:[
{
type: String
}
],
followings:[
{
type: String
}
],
posts:[{
type: mongoose.Schema.Types.ObjectId,
ref: "Post"
}]
});
如何解决此问题?