问题描述
const userSchema = new Schema({
username: {
type: String,},email: {
type: String,thumbnail: {
type: String,default: backendURL + "images/blank-profile.png"
}
})
const imageSchema = new Schema({
src: {
type: String,name: {
type: String,user: {
id: { type: String,required: true },thumbnail: { type: String },username: { type: String }
},comments: [{
comment: String,username: { type: String }
},}]
})
这很好,但是有问题。当用户尝试更改缩略图或用户名时,我需要更新整个图像以及与用户有任何关系的图像注释。我认为这将是非常繁琐的查询。 另一个选择是,如果我将图像架构设置为这样
const imageSchema = new Schema({
src: {
type: String,user:{type: String},userId:String
}]
})
,当我获取图像时,我还会为用户运行查询,这样我将获得包含用户信息的图像。但这也可能是沉重的代码,因为我将为所有用户运行查询。但是如果我这样做,则当用户更改自己的缩略图或用户名时,不需要更新用户。
我不知道哪种方式最适合我的情况。你们有什么主意或其他解决方案吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)