Professional Documents
Culture Documents
08 Activity 1
08 Activity 1
08 Activity 1
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"],
}
])
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}})
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);