I have been developing an app for renting flats for a personal project of mine. I have been wondering about how to build/implement an inbox system to the current app which uses mongodb as database.
What does matter in such a feature? Would it be possible to define a schema called messages ?
var MessageSchema = new mongoose.Schema({
message: String,
sender : {
id : {
type : mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
}
recipient : {
id : {
type : mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
}
)};
If I were to send a message to user y then it would be stored as recipient and the x value would be the sender. When I want to render a page called inbox could i do Messages.find({req.user._id) to sort all messages ? I am a bit lost in regards to the schema design.
via Ozan
No comments:
Post a Comment