0% found this document useful (0 votes)
46 views3 pages

MONGODB Problem Solving Ques

The document outlines basic CRUD operations for MongoDB, including inserting, querying, updating, and deleting employee records, as well as intermediate tasks like aggregation and indexing. It also covers advanced concepts such as embedded documents, working with arrays, and transactions, along with tasks related to a social media platform and a library management system. Each section provides specific tasks to perform with example data structures.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

MONGODB Problem Solving Ques

The document outlines basic CRUD operations for MongoDB, including inserting, querying, updating, and deleting employee records, as well as intermediate tasks like aggregation and indexing. It also covers advanced concepts such as embedded documents, working with arrays, and transactions, along with tasks related to a social media platform and a library management system. Each section provides specific tasks to perform with example data structures.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MONGODB

Basic CRUD Operations


1. Insert Documents:
o Insert 5 employee records into a employees collection with fields: { id, name,
age, department, salary }.
o Ensure at least two employees belong to the same department.
2. Querying Data:
o Find all employees who work in the "IT" department.
o Retrieve employees whose salary is greater than 50,000.
o Find employees whose name starts with "A".
3. Updating Documents:
o Increase the salary of all employees in the "HR" department by 10%.
o Change the department of an employee named "John" to "Finance".
4. Deleting Documents:
o Remove all employees with a salary less than 30,000.
o Delete a single employee record where name = "Alice".
Intermediate Aggregation & Indexing
5. Aggregation Framework:
o Find the total salary paid to employees in each department.
o Count the number of employees in each department.
o Find the average salary of employees.
6. Indexing:
o Create an index on the name field to speed up search operations.
o Create a compound index on department and salary.
Advanced Concepts
7. Embedded Documents & Relationships:
o Insert an employee record with an embedded address field: {street, city, state,
zip}.
o Retrieve employees who live in "New York".
8. Working with Arrays:
o Insert a document in a students collection with subjects as an array: {name,
subjects: ["Math", "Science", "English"]}.
o Find students who have "Math" in their subjects.
o Add a new subject "History" to a student named "David".
9. Transactions:
o Implement a transaction where an employee’s salary is deducted, and the
deducted amount is recorded in a transactions collection.

Social Media Platform


Your company runs a social media platform where users store posts in the posts collection:
{
"_id": ObjectId("..."),
"user": "john_doe",
"content": "MongoDB is awesome!",
"likes": 50,
"comments": [
{"user": "alice", "comment": "I agree!"},
{"user": "bob", "comment": "Great post!"}
],
"tags": ["MongoDB", "Database"],
"timestamp": ISODate("2024-03-29T12:00:00Z")
}
Tasks:
• Find posts with more than 100 likes.
• Retrieve posts containing the tag "MongoDB".
• Count the total number of comments on all posts.
• Find the most active users based on the number of posts created.
Library Management System
A library stores book records in the following format:
json
CopyEdit
{
"_id": ObjectId("..."),
"title": "MongoDB Guide",
"author": "John Doe",
"publishedYear": 2022,
"genres": ["Technology", "Database"],
"availableCopies": 5,
"borrowedBy": [
{ "userId": 101, "borrowedDate": "2024-03-20" },
{ "userId": 102, "borrowedDate": "2024-03-22" }
]
}
Tasks:
• Find books that belong to the "Technology" genre.
• Retrieve books that were published after 2020.
• Find books that have been borrowed by more than one user.
• Decrease availableCopies when a book is borrowed.

*********************************

You might also like