r/mongodb • u/RelativeMaster8348 • 15h ago
I m new to mongo db and have to upload this assignment now This assignment needs to be done in MongoDB using mongosh (MongoDB Shell) or MongoDB Compass
i want screenshots to upload Please 1. Q1
5 marks
Create the four collections (mentioned in Problem Statement) in MongoDB.\
For posts and comments, justify in one line each whether userId should be embedded (storing user details directly inside the document) or referenced (storing only the _id and looking it up separately), and implement the chosen design consistently across all four collections.\
Insert one sample document into each collection and display it with find() to confirm the structure before proceeding.
Drag & drop or click to browsePDF, ZIP, DOCX, PNG, JPG, DOC, TXT up to 25MB · max 1 fileQ2. Data Population
5 marks
Q2 Insert at least 6 users, 10 posts (across different users), 15 comments (across different posts) and 20 likes (across different posts/users), ensuring enough variety to support later aggregation (e.g., at least one user with multiple posts, at least one post with no comments).
Then perform: (a) find() with a filter (e.g., posts by one specific user), (b) updateOne() to edit a post's content, (c) deleteOne() to remove one comment, showing the collection state after each operation.
Drag & drop or click to browsePDF, DOCX, DOC, JPG, PNG, ZIP, TXT up to 25MB · max 1 file
Q3. Aggregation pipelines
5 marks
Write three aggregation pipelines using $match, $group and $sort: (a) total likes per post, sorted descending, (b) total posts per user, (c) average number of comments per post across the whole posts collection.
Use $lookup in at least one pipeline to join posts with users and display the user's name alongside their post's like count.
Drag & drop or click to browsePDF, ZIP, TXT, DOCX, PNG, DOC, JPG up to 25MB · max 1 file
4. Q4. Index
5 marks
Create a single-field index on posts.userId and a compound index on comments covering postId and createdAt.
Re-run one query from Q3 before and after creating the relevant index, and compare the output of explain("executionStats") (documents examined, execution time) for both runs.
Drag & drop or click to browsePDF, ZIP, TXT, DOCX, PNG, DOC, JPG up to 25MB · max 1 file
You can submit once. Make sure all files are added.
Submit
Give each image for each question seperate