Mongobd2

 ASSIGNMENT 2





1] Create a database with the name 'Company' 


> use Company

switched to db Company




2] 'Employee' Collection


> db.createCollection('Employee')

{ "ok" : 1 }

 



QUERIES:


1]Insert atleast 5 documents in ‘Employee’ collection.


>db.Employee.insert({id:'10', fname:'Iffat', lname:'Chichkar', email:'abc@gmail.com' ,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'})

WriteResult({ "nInserted" : 1 })



>db.Employee.insert({id:'11', fname:'Aishwarya', lname:'Cholayil', email:'xyz@gmail.com', 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'})

WriteResult({ "nInserted" : 1 })



>db.Employee.insert({id:'12', fname:'Aayesha', lname:'Tamboli', email:'pqr@gmail.com', 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'})

WriteResult({ "nInserted" : 1 })





2]Insert multiple documents (atleast 10) into the transaction collection by passing an array of documents to the db.collection.insert() method.


> db.transaction.insert([

... {

... tid:101,

...  tdate:24/07/2019,

...  name:'Iffat',

...  tdetails:[{

...  id:201,

...  item:'Chocolate',

... quantity:'2',

... price:200}],

... payment:[{

... typeofpayment:'Debit',

... totalpaidamount:200,

...  paymentsuccessfull:'Yes'}],

... Remark:'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'

... }])





3] Display all the documents of both the collections in a formatted manner.


> db.Employee.find().pretty()

{

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

"id" : "10",

"fname" : "Iffat",

"lname" : "Chichkar",

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

"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" : "Aishwarya",

"lname" : "Cholayil",

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

"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" : "Aayesha",

"lname" : "Tamboli",

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

"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" : "Aishwarya",

"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}})





5] Update the remark for transaction id 201.


> db.transaction.update({tid:101},{$set:{Remark:'successfull'}})

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })





6] Update the designation of an employee named “_______ “ from superviser  to manager.


> db.Employee.update({fname:'Iffat'},{$set:{designation:'Manager'}})

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

/1999"




7] Update designation of an employee having Employee id as_______.


> db.Employee.update({id:'11'},{$set:{designation:'Manager'}})

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })





8] Change the address of an employee having Employee id as _______.


> 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 })





9] Delete the transaction made by “_______” employee on the given date.


> db.transaction.deleteOne({name:'Aishwarya'},{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" : "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"

}





> 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"

}

Comments

Popular posts from this blog

Mongodb3

Mongodb4

Mongodb1