How do you design a data model for a social media platform using MongoDB

0 votes
With the help of proper code example can you tell me How do you design a data model for a social media platform using MongoDB?
Feb 22 in Node-js by Ashutosh
• 20,870 points
46 views

1 answer to this question.

0 votes

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

}

answered Feb 23 by Kavya

Related Questions In Node-js

0 votes
1 answer

How do you design a schema for tree structures in MongoDB?

Designing a schema for tree structures in ...READ MORE

answered Feb 22 in Node-js by Kavya
46 views
0 votes
1 answer

How do you embed a document in MongoDB for better performance?

Embedding documents in MongoDB is a common ...READ MORE

answered Feb 22 in Node-js by Kavya
68 views
0 votes
1 answer
0 votes
1 answer

How do you run a js file using npm scripts?

Hello @kartik, Try this: { "scripts" : { ...READ MORE

answered Oct 12, 2020 in Node-js by Niroj
• 82,840 points
11,699 views
0 votes
1 answer

What is the difference between RDBMS relationships and MongoDB’s data model?

Feature RDBMS (SQL Databases) MongoDB (NoSQL Document Database) Data Structure Tables ...READ MORE

answered Feb 23 in Node-js by Kavya
46 views
0 votes
1 answer

Write a query for a compound index to optimize a search operation in MongoDB.

A compound index improves search performance by ...READ MORE

answered Feb 23 in Node-js by Kavya
56 views
0 votes
1 answer

How do you handle concerns for write operations in MongoDB?

Write operations in MongoDB need to be ...READ MORE

answered Feb 23 in Node-js by Kavya
102 views
0 votes
1 answer

Write a query to fetch specific fields using MongoDB projections.

Fetching Specific Fields Using MongoDB Projections MongoDB projections ...READ MORE

answered Feb 23 in Node-js by Kavya
63 views
0 votes
1 answer

How do you model a many-to-many relationship in MongoDB with an example?

In MongoDB, a many-to-many relationship can be ...READ MORE

answered Feb 23 in Node-js by Kavya
69 views
0 votes
1 answer

What are MongoDB data types, and how do you define them in a schema?

MongoDB supports various data types, including: String (String) ...READ MORE

answered Feb 23 in Node-js by anonymous
86 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP