Design a MongoDB data model for a social media platform with the following collections:
Users:
{
"_id": ObjectId,
"username": String,
"email": String,
"passwordHash": String,
"profilePic": String,
"bio": String,
"followers": [ObjectId], // Array of User IDs
"following": [ObjectId] // Array of User IDs
}
Posts:
{
"_id": ObjectId,
"userId": ObjectId, // Reference to the User
"content": String,
"media": [String], // Array of URLs
"timestamp": Date,
"likes": [ObjectId], // Array of User IDs
"comments": [
{
"userId": ObjectId,
"text": String,
"timestamp": Date
}
]
}
Notifications:
{
"_id": ObjectId,
"userId": ObjectId, // Reference to the User
"type": String, // e.g., "like", "comment", "follow"
"sourceUserId": ObjectId, // User who triggered the notification
"postId": ObjectId, // Optional, for post-related notifications
"timestamp": Date,
"read": Boolean
}
Messages:
{
"_id": ObjectId,
"senderId": ObjectId,
"receiverId": ObjectId,
"content": String,
"timestamp": Date,
"read": Boolean
}