在我的React社交媒体项目中,我想添加一个“好友连接请求”功能。我使用MongoDB,下面是我的“用户模型”。
现在我的“朋友”都窝在里面了
UserSchema
,但觉得这样不对。
-
如果我想要更多的数据,比如
pending, rejected, block sender...
-
假设:用户A向B发送了连接请求,那么B应该知道,当B尝试向朋友发送请求时,A应该被排除在外。
const UserSchema = new Schema({
username: {
type: String,
required: [true, 'User Name is required'],
lowercase: true,
},
email: {
type: String,
required: [true, 'Email or Phone number is required'],
unique: true,
lowercase: true,
},
password: {
type: String,
required: [true, 'Password is required'],
},
thumbnail: {
type: String,
default: 'https://cdn.pixabay.com/photo/2016/08/09/17/52/instagram-1581266_960_720.jpg',
},
createAt: {
type: Date,
default: Date.now,
},
friends: [
{
type: Schema.Types.ObjectId,
ref: 'user',
}
],
}),
我是新手,第一次遇到这种问题,不知道这个功能背后的设计逻辑。有经验的人可以给我一些进展(欢迎所有的前端和后端,数据库设计)?