0% found this document useful (0 votes)
94 views

FullStack Assignment

The document contains 25 questions and solutions related to updating employee documents in a MongoDB database collection. The updates include modifying field values, adding/removing projects and skills, incrementing/decrementing values, and filtering documents based on field criteria.

Uploaded by

Vidisha singhal
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)
94 views

FullStack Assignment

The document contains 25 questions and solutions related to updating employee documents in a MongoDB database collection. The updates include modifying field values, adding/removing projects and skills, incrementing/decrementing values, and filtering documents based on field criteria.

Uploaded by

Vidisha singhal
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/ 5

Name- Ankur Gautam Section: D-(10) University Roll-No: 201500102

Full Stack Assignment

Q1. All Employee’s with the desg as ‘CLERK’ are now called as (AO)
Administrative Officers. Update the Employee collection for this.

Sol. db.Employee.updateMany({ designation: "CLERK" },{ $set: { designation:


"AO" } })

Q2. Change the number of hours for project-1 to 5 for all employees
with designation analyst.
Sol. db.employees.updateMany({ "designation": "analyst" },{ $set: { "project-
1.hours": 5 } })

Q3. Add 2 projects project-3 and project-4 for employee whose name
starts with ”Deep” with 2 hrs
Sol. db.employees.updateMany({ name: { $regex: /^Deep/ } },{ $push: {
projects: { name: "project-3", hours: 2 } } },{ $push: { projects: { name:
"project-4", hours: 2 } } })

Q4. Add bonus rs 2000 for all employees with salary > 50000 and
1500 if salary <50000 and > 30000 otherwise bonus will be 1000

Sol. db.employees.updateMany({}, [{$set: {bonus: {$cond: {if: { $gte:


["$salary", 50000] },then: 2000, else: {$cond: {if: { $gte: ["$salary", 30000]
},then: 1500, else: 1000}}}}}}])

Q5. Change manager name to Tushar for all employees whose


manager is currently “satish” And manager number to 3333
Sol. db.employees.updateMany({ manager: "satish" },{ $set: { manager:
"Tushar", managerNumber: 3333 } })

Q6. Increase salary of all employees from “purchase department” by


15000
Sol. db.employees.updateMany({ department: "purchase department" },{ $inc:
{ salary: 15000 } })

Q7. Decrease number of hrs by 2 for all employees who are working
on project-2
Sol. db.employee.updateMany({ project: "project-2" },{ $inc: { hrs: -2 } })

Q8. Delete project-2 from all employee document if they are working
on the project for 4 hrs.

Sol. db.employees.updateMany( { "projects.projectName": "project-2",


"projects.hoursWorked": 4 },{ $pull: { projects: { projectName: "project-2" } }
})

Q9. Change the salary of employees to 10000 only if their salary is <
10000

Sol. db.employees.updateMany({ salary: { $lt: 10000 } },{ $set: { salary:


10000 } })

Q10. Increase bonus of all employees by 500 if the bonus is <2000 or


their salary is < 20000 or if employee belong to sales department

Sol. db.employee.updateMany({$or: [{ bonus: { $lt: 2000 } },{ salary: { $lt:


20000 } },{ department: "Sales" }]},{ $inc: { bonus: 500 } })

Q11. Add 2 new project at position 2 for all employees with


designation analyst or salary is equal to either 30000 or 33000 or
35000

Sol. db.employees.updateMany({$or: [{ designation: "analyst" },{ salary: { $in:


[30000, 33000, 35000] } }] },{$push: {projects: {$each: [{ name: "New Project
1", position: 2 }, { name: "New Project 2", position: 2 }],$position: 2}}})

Q12. Delete last project of all employees with department name is


“HR” and if the location is Mumbai
Sol. db.collection.updateMany({ department: "HR", location: "Mumbai" },{
$pop: { projects: 1 } })

Q13. Change designation of all employees to senior programmer if


they are working on name:”Project-1” for 4 hrs

Sol. db.collection.updateMany({ name: "Project-1", hours_worked: { $gte: 4 }


},{ $set: { designation: "Senior Programmer" } })

Q14. Add list of hobbies in all employees document whose manager is


Rajan or Revati

Sol. db.employees.updateMany( { $or: [ { manager: "Rajan" }, { manager:


"Revati" } ] }, { $set: { hobbies: [ "hobby1", "hobby2", "hobby3" ] } })

Q15. Add list of skillset in all employee documents who are working
on project-4 for 3 hrs or on project-3 for 4 hrs

Sol. db.employees.updateMany({$or: [{"projects.name": “Project-3”,


"projects.hours": 4},{"projects.name": “Project-4”, "projects.hours":
3}]},{$addToSet: {skills: {$each: ["MongoDB", "AngularJS"]}}})

Q16. Add a new hobby as blogging at 3 position in hobbies array for


all employess whose name starts with R or p and ends with j or s
Sol. db.employees.updateMany({$and: [{ name: { $regex: /^R|^P/ } },{ name: {
$regex: /j$|s$/ } }] }, { $push: { hobbies: { $each: [ "blogging" ], $position: 2 }
} })

Q17. Increase salary by 10000 for all employees who are working on
project-2 or project-3 or project-1 Decrease bonus by 1000 rs And
increase salary by 1000rs for all employees whose department
location is Mumbai

Sol. db.employees.updateMany({ projects: { $in: ["project-1", "project-2",


"project-3"] } },{ $inc: { salary: 10000 } })

db.employees.updateMany({ departmentLocation: "Mumbai" },{ $inc: { bonus:


-1000, salary: 1000 } })
Q18. Remove all employees working on project-1

Sol. db.employees.deleteMany({ “projects.name”: "project-1" })

Q19. Replace document of employee with name “Deepak to some new


document
Sol. db.employees.updateOne({ name: "Deepak" },{$set: {name: "New
Name",age: 25,department: "New Department"}})

Q20. Change skill python to python 3.8 for all employees if python is
there in the skillset
Sol. db.employees.updateMany({ skills: "python" },{ $set: { "skills.$": "python
3.8" } })

Q21. Add 2 skills MongoDb and Perl at the end of skillset array for all
employees who are working at Pune location
Sol. db.employees.updateMany({ location: "Pune" },{ $push: { skillset: {
$each: ["MongoDb", "Perl"] } } })

Q22. Delete first hobby from hobby array for all employees who are
working on project-1 or project-2

Sol. db.employee.updateMany({"projects": {"$elemMatch": {"name": {"$in":


["project-1","project-2"]}}}},{"$pop": {"hobbies": -1}})

Q23. Delete last hobby from hobbies array for all employees who are
working on project which is at 2 nd position in projects array for 4
hrs

Sol. db.collection.updateMAny({projects: { $size: 2 }, "projects.1.hours": 4},{


$pop: { hobbies: 1 } })

Q24. Add 2 new projects at the end of array for all employees whose
skillset contains Perl or python
Sol. db.employees.updateMany({ "skillset": { $in: ["Perl", "Python"] } },{
$push: { "projects": { $each: ["New Project 1", "New Project 2"] } } })
Q25. Change hrs to 6 for project-1 for all employees if they working
on the project-1 for < 6 hrs. otherwise keep the existing value.
Sol. db.employees.updateMany({ "project": "project-1", "hrs": { $lt: 6 } },{
$set: { "hrs": 6 } })

You might also like