Mongodb 2
Mongodb 2
2] 'Employee' Collection
> db.createCollection('Employee')
{ "ok" : 1 }
QUERIES:
2]Insert multiple documents (atleast 10) into the transaction collection by passing an array of
documents to the db.collection.insert() method.
>
db.transaction.insertMany([{tid:101,tdate:24/07/2019,name:'Iffat',tdetails:[{id:201,item:'Chocolate',quanti
ty:'2',price:200}],payment:[{typeofpayment:'Debit',totalpaidamount:200,paymentsuccessfull:'Yes'}],Rem
ark:'null'},{tid:102,tdate:25/07/2019,name:'Aishwarya',tdetails:[{id:202,item:'Book',quantity:'2',price:100
}],payment:[{typeofpayment:'Cash',totalpaidamount:100,paymentsuccessfull:'Yes'}],Remark:'null'}])
> db.Employee.find().pretty()
{
"_id" : ObjectId("5d882bd60cf0806c8460b5ba"),
"id" : "10",
"fname" : "Saniya",
"lname" : "Nadaf",
"email" : "[email protected]",
"pno" : "8021549632",
"addr" : [
{
"hno" : "286",
"street" : "Bhawani peth",
"city" : "Pune",
"state" : "Maharashtra",
"country" : "India",
"pincode" : "411042"
}
],
"salary" : "35,000",
"designation" : "CSS",
"experience" : "Fresher",
"Dateofjoining" : "19/06/2019",
"birthdate" : "26/01/1999"
}
{
"_id" : ObjectId("5d8834f17e407c00d1ee2d9e"),
"id" : "11",
"fname" : "Ayesha",
"lname" : "Shaikh",
"email" : "[email protected]",
"pno" : "9964752103",
"addr" : [
{
"hno" : "18",
"street" : "Undri",
"city" : "Pune",
"state" : "Maharashtra",
"country" : "India",
"pincode" : "411060"
}
],
"salary" : "20,000",
"designation" : "Associate",
"experience" : "Fresher",
"Dateofjoining" : "19/07/2019",
"birthdate" : "06/07/1998"
}
{
"_id" : ObjectId("5d8835cd7e407c00d1ee2d9f"),
"id" : "12",
"fname" : "Soleha",
"lname" : "Sayyed",
"email" : "[email protected]",
"pno" : "8236427026",
"addr" : [
{
"hno" : "254",
"street" : "Dattawadi",
"city" : "Pune",
"state" : "Maharashtra",
"country" : "India",
"pincode" : "411030"
}
],
"salary" : "50,000",
"designation" : "Manager",
"experience" : "Fresher",
"Dateofjoining" : "25/07/2019",
"birthdate" : "26/06/1999"
}
> db.transaction.find().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" : "null"
}
{
"_id" : ObjectId("5d8833847e407c00d1ee2d9d"),
"tid" : 102,
"tdate" : 0.0017689096440953796,
"name" : "Ayesha",
"tdetails" : [
{
"id" : 202,
"item" : "Book",
"quantity" : "2",
"price" : 100
}
],
"payment" : [
{
"typeofpayment" : "Cash",
"totalpaidamount" : 100,
"paymentsuccessfull" : "Yes"
}
],
"Remark" : "null"
}
4] Update salary of all employees by giving an increment of Rs.4000
> db.Employee.update({id:10},{$inc:{salary:4000}})
> db.transaction.update({tid:101},{$set:{Remark:'successfull'}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.Employee.update({fname:'Saniya'},{$set:{designation:'Manager'}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
/1999"
> db.Employee.update({id:'11'},{$set:{designation:'Manager'}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.Employee.update({id:'10'},{$set:{addr:[{hno:'20',street:'MG.
Road',city:'Pune',state:'Maharashtra',country:'India',pincode:'411028'}]}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.transaction.deleteOne({name:'Ayesha'},{tdate:25/07/2019})
{ "acknowledged" : true, "deletedCount" : 1 }
10] Delete all the employees whose first name starts with ‘K’.
> db.Employee.deleteMany({fname:/^A/})
{ "acknowledged" : true, "deletedCount" : 2 }
> db.Employee.find().pretty()
{
"_id" : ObjectId("5d882bd60cf0806c8460b5ba"),
"id" : "10",
"fname" : "Saniya",
"lname" : "Nadaf",
"email" : "[email protected]",
"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"
}
> db.transaction.find().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"
}