0% found this document useful (0 votes)
128 views8 pages

Laboratory

The document creates a collection called "employees" in the MongoLab database. It inserts multiple employee documents with fields like name, salary, position, etc. It then performs various operations like deleting a document, updating documents to change the "ReportingTo" field, finding documents that match certain criteria, and updating all documents to add a "contact" field.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views8 pages

Laboratory

The document creates a collection called "employees" in the MongoLab database. It inserts multiple employee documents with fields like name, salary, position, etc. It then performs various operations like deleting a document, updating documents to change the "ReportingTo" field, finding documents that match certain criteria, and updating all documents to add a "contact" field.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

use MongoLab1

db.createCollection(“employees”)

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']}

]);

db.employees.deleteOne(

{ReportingTo: null}

)
db.employees.updateOne(

{Name: “Reg Rubio”},

{$set:{ReportingTo:[‘President’]}}
)

db.employees.updateOne(

{Name: “Ian Tayao”},

{$set:{ReportingTo:[‘President’]}}

)
db.employees.findOne(

{Salary:{$gt: 21000.00}}

)
Db.employees.findOne(
{ReportingTo:{$not:{$in: [‘President’]}}}

db.employees.updateMany( {id: 1},{$set: {"contact": {"email": "steve.badiola.gov.ph", "phone": "+1


1234567"}}}, {id: 2},{$set: {"contact": {"email": "jamir.garcia.gov.ph", "phone": "+2 1234567"}}}, {id: 3},
{$set: {"contact": {"email": "reg.rubio.gov.ph", "phone": "+3 1234567"}}}, {id: 4},{$set: {"contact":
{"email": "ian.tayao.gov.ph", "phone": "+4 1234567"}}} )

You might also like