r/AskProgramming • u/DreamIce • Aug 17 '22
Databases Friend System like facebook
hello guys im trying to implement a friend system like facebook, i came up with this schema, any thoughts? my plan is im going to create a friendrequest document every time a user send a request, then when the receiver accepted the request update the status to friends then add the sender and receiver id to each friends array, any thoughts on how i could improve this
const FriendRequestModel = new mongoose.Schema({from: {type: String,// could be the id that sent the user request?},to: {type: String,// could be the id of the user send his request to?},status: {type: String,// values could me requested, friends, notfriend/addfriend?/, pending request?, rejected},})
const UserSchema = new mongoose.Schema({username: {type: String,required: true},email: {type: String,required: true,unique: true},password: {type: String,required: true},role: {type: String,required: true}// friends: [{ type: Schema.Types.ObjectId, ref: "User" }],})