Mongodb4

 ASSIGNMENT 4





1] Sort the employees in the descending order of their designation. 

> db.Employee.find().sort({designation:-1}).pretty()

{

 "_id" : ObjectId("5d882bd60cf0806c8460b5ba"),

 "id" : "10",

 "fname" : "Iffat",

 "lname" : "Chichkar",

 "email" : "abc@gmail.com",

 "pno" : "8021549632",

 "addr" : [

  {

   "hno" : "20",

   "street" : "MG. Road",

   "city" : "Pune",

   "state" : "Maharashtra",

   "country" : "India",

   "pincode" : "411028"

  }

 ],

 "salary" : "35,000",

 "designation" : "Manager",

 "experience" : "Fresher",

 "Dateofjoining" : "19/06/2019",

 "birthdate" : "26/01/1999"

}





2] Count the total number of employees in a collection. 

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

1







3] Calculate the sum of total amount paid for all the transaction documents. 

> db.transaction.aggregate({$group:{_id:'$name',Total:{$sum:'$price'}}}).pretty()

{ "_id" : "Iffat", "Total" : 0 }





4] Calculate the sum of total amount paid for each payment type. 

> db.transaction.aggregate({$group:{_id:'$name',Total:{$sum:'$typeofpayment'}}}).pretty()

{ "_id" : "Iffat", "Total" : 0 }

> db.transaction.find().sort({_id:-1}).pretty()

{

 "_id" : ObjectId("5d8833847e407c00d1ee2d9c"),

 "tid" : 101,

 "tdate" : 0.0016981532583315642,

 "name" : "Iffat",

 "tdetails" : [

  {

   "id" : 201,

   "item" : "Chocolate",

   "quantity" : "2",

   "price" : 200

  }

 ],

 "payment" : [

  {

   "typeofpayment" : "Debit",

   "totalpaidamount" : 200,

   "paymentsuccessfull" : "Yes"

  }

 ],

 "Remark" : "successfull"

}





5] Find designation of employees who have made transaction of amount greater than Rs. 100. 

> db.transaction.find({'payment.totalpaidamount':{$gt:100}}).pretty()

{

 "_id" : ObjectId("5d8833847e407c00d1ee2d9c"),

 "tid" : 101,

 "tdate" : 0.0016981532583315642,

 "name" : "Iffat",

 "tdetails" : [

  {

   "id" : 201,

   "item" : "Chocolate",

   "quantity" : "2",

   "price" : 200

  }

 ],

 "payment" : [

  {

   "typeofpayment" : "Debit",

   "totalpaidamount" : 200,

   "paymentsuccessfull" : "Yes"

  }

 ],

 "Remark" : "successfull"

}

Comments

Popular posts from this blog

Mongodb3

Mongodb1