08 Activity 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Oriel, ericka jannelle

BT501A

1. Employees collection
db.employees.insertMany([
{
"_id": 1,
"Name" : "Steve Badiola",
"Salary" : 16099.55,
"Position" : "President",
"Rank" : 1,
"ReportingTo" : null,
},

{
"_id" : 2,
"Name" : "Jamir Garcia",
"Salary" : 14567.12,
"Position" : "Vice-President",
"Rank" : 2,
"ReportingTo" : ["President"],
},

{
"_id" : 3,
"Name" : "Reg Rubio",
"Salary" : 13891.22,
"Position" : "Secretary",
"Rank" : 3,
"ReportingTo": ["Vice-President"],
},

{
"_id" : 4,
"Name" : "Ian Tayao",
"Salary" : 13000,
"Position" : "Treasurer",
"Rank" : 4,
"ReportingTo" : ["Secretary", "Vice-President"],
}
])

2. Remove all the reporting to where the value is null


db.employees.updateMany(
{"ReportingTo":null},
{"$unset" : {"ReportingTo":null}}
)

3. using $inc operate, update all salary by 5000


db.employees.updateMany(
{},{"$inc":{"Salary":5000}}
)

4. Update reg rubio and Ian tayao by adding president to their reporting field
db.employees.updateMany(
{"$or": [{"Name": "Reg Rubio"},{"Name": "Ian Tayao"}]},
{"$push":{"ReportingTo":"President"}})
5. Find the salary above 21000
db.employees.find(
{"Salary":{"$gt":21000.00}})

6. Find the name start S and R


db.employees.find(
{"$or":[{"Name": /^s/i},{"Name": /^r/i}]}
)

7. Find the document is not reporting president


db.employees.find({"ReportingTo" : {"$not":{"$in":["President"]}}})

8. Update all the document by adding a sub documnet name contact with a key value, email
name@gov.ph
var pres = db.employees.findOne({"Rank":1});
pres.contact = {"email":"steve.badiola@gov.ph", "phone" : "+1 1234567"};
db.employees.replaceOne({"Rank":pres.Rank},pres);

var vp = db.employees.findOne({"Rank":2});
vp.contact = {"email":"jamir.garcia@gov.ph","phone":"+2 1234567"};
db.employees.replaceOne({"Rank":vp.Rank},vp);

var sec = db.employees.findOne({"Rank":3});


sec.contact = {"email":"reg.rubio@gov.ph","phone":"+3 1234567"};
db.employees.replaceOne({"Rank":sec.Rank},sec);

var trea = db.employees.findOne({"Rank":4});


trea.contact = {"email":"ian.tayao@gov.ph","phone":"+4 1234567"};
db.employees.replaceOne({"Rank":trea.Rank},trea);

You might also like