[go: up one dir, main page]

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

Assignment 4 Mongo DB

The document contains a series of MongoDB queries and their results related to employee and transaction data. It includes queries for finding employees by designation, filtering by name patterns, sorting by salary, counting records, and aggregating payment amounts. Additionally, it demonstrates the use of map-reduce for summarizing transaction details.

Uploaded by

yash borkar
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)
54 views3 pages

Assignment 4 Mongo DB

The document contains a series of MongoDB queries and their results related to employee and transaction data. It includes queries for finding employees by designation, filtering by name patterns, sorting by salary, counting records, and aggregating payment amounts. Additionally, it demonstrates the use of map-reduce for summarizing transaction details.

Uploaded by

yash borkar
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

ASSIGNMENT 4

1) > db.Employee.find({$or:[{Designation:"Manager"},{Designation:"Floor
Supervisor"}]},{_id:0,First_Name:1,Designation:1}).pretty()
{ "First_Name" : "Rohit", "Designation" : "Manager" }
{ "First_Name" : "Arnav", "Designation" : "Floor Supervisor" }

2) > db.Employee.find({First_Name:/r$/},{_id:0,First_Name:1,Eid:1}).pretty()
{ "Eid" : 3, "First_Name" : "Onkar" }

3) >
db.Employee.find({Salary:{$gt:30000}},{_id:0,First_Name:1,Eid:1,Salary:1}).sort({Salary:1}).pretty()
{ "Eid" : 2, "First_Name" : "Kailas", "Salary" : 35000 }
{ "Eid" : 1, "First_Name" : "Rohit", "Salary" : 50000 }

4) db.Employee.find({},{First_Name:1,Eid:1,_id:0,Designation:1}).sort({Designation:-1}).pretty()
{ "Eid" : 2, "First_Name" : "Kailas", "Designation" : "Supervisor" }
{ "Eid" : 1, "First_Name" : "Rohit", "Designation" : "Manager" }
{ "Eid" : 4, "First_Name" : "Arnav", "Designation" : "Floor Supervisor" }
{ "Eid" : 3, "First_Name" : "Onkar", "Designation" : "Developer" }
{ "Eid" : 5, "First_Name" : "Abhijit", "Designation" : "Accountant" }

5) > db.Employee.find().count()
5

6) > db.Transaction.aggregate([{$group:{_id:null,Sum:{$sum:{$sum:"$Payment.Paid_amt"}}}}])
{ "_id" : null, "Sum" : 111900 }

7) >
db.Transaction.aggregate([{$group:{_id:"$Payment.Type",Sum:{$sum:{$sum:"$Payment.Paid_amt"}}}}
])
{ "_id" : [ "Debit" ], "Sum" : 38000 }
{ "_id" : [ "Cash" ], "Sum" : 7400 }
{ "_id" : [ "Credit" ], "Sum" : 66500 }

8) > db.Transaction.find({},{Tid:1,_id:0,TDate:1}).sort({TDate:-1}).limit(1).pretty()
{ "Tid" : 701, "TDate" : "20/07/2019" }

9) >
db.Transaction.aggregate([{$match:{"Payment.Paid_amt":{$gt:500}}},{$lookup:{from:"Employee",loca
lField:"Name",foreignField:"First_Name",as:"Payee"}},{$project:{_id:0,Name:1,"Payment.Paid_amt":1,
Payee:{"Designation":1}}}]).pretty()
{
"Name" : "Arnav",
"Payment" : [
{
"Paid_amt" : 60000
}
],
"Payee" : [
{
"Designation" : "Floor Supervisor"
}
]
}
{
"Name" : "Arnav",
"Payment" : [
{
"Paid_amt" : 35000
}
],
"Payee" : [
{
"Designation" : "Floor Supervisor"
}
]
}
{
"Name" : "Abhijit",
"Payment" : [
{
"Paid_amt" : 1000
}
],
"Payee" : [
{
"Designation" : "Accountant"
}
]
}
{
"Name" : "Onkar",
"Payment" : [
{
"Paid_amt" : 900
}
],
"Payee" : [
{
"Designation" : "Developer"
}
]
}
{
"Name" : "Onkar",
"Payment" : [
{
"Paid_amt" : 2000
}
],
"Payee" : [
{
"Designation" : "Developer"
}
]
}
{
"Name" : "Abhijit",
"Payment" : [
{
"Paid_amt" : 5000
}
],
"Payee" : [
{
"Designation" : "Accountant"
}
]
}
{
"Name" : "Rohit",
"Payment" : [
{
"Paid_amt" : 3000
}
],
"Payee" : [
{
"Designation" : "Manager"
}
]
}
{
"Name" : "Kailas",
"Payment" : [
{
"Paid_amt" : 4000
}
],
"Payee" : [
{
"Designation" : "Supervisor"
}
]
}
>

10) > function map(){emit(this.TDetails.IName,this.TDetails.Quantity)}function


reduce(key,value){return
Array.sum(value)}db.Transaction.mapReduce(map,reduce,{out:"Map-Example"})
{
"result" : "Map-Example",
"timeMillis" : 408,
"counts" : {
"input" : 10,
"emit" : 10,
"reduce" : 1,
"output" : 1
},
"ok" : 1
}

You might also like