Friday, February 1, 2019

Create "THACHER" db and Queries

Create a new MONGODB database called “TEACHER”




INSERT


No
Documents / Queries
0
db.TEACHER_MASTER.insert({
   _id : Uniqe_Id,
   Name : "Name",
   Subject : ["Array_1","Array_2","Array_N"],
   DOB : ISODate("YYYY-MM-DD"),
   Gender : "Male/Female",
   City : "City_Name"
})
1
db.TEACHER_MASTER.insert({
   _id : 1001,
   Name : "Nimit",
   Subject : ["PHP","Laravel","Android"],
   DOB : ISODate("1997-06-19"),
   Gender : "Male",
   City : "Rajkot"
})
2
db.TEACHER_MASTER.insert({
   _id : 1002,
   Name : "Nishit",
   Subject : ["ASP.Net","React"],
   DOB : ISODate("1998-01-23"),
   Gender : "Male",
   City : "Rajkot"
})
3
db.TEACHER_MASTER.insert({
   _id : 1003,
   Name : "Nirajbhai",
   Subject : ["ASP.Net","Java","Android"],
   DOB : ISODate("1995-01-07"),
   Gender : "Male",
   City : "Katch"
})
4
db.TEACHER_MASTER.insert({
   _id : 1004,
   Name : "Dipen",
   Subject : ["PHP","MongoDB","Laravel"],
   DOB : ISODate("1997-11-13"),
   Gender : "Male",
   City : "Anjar"
})
5
db.TEACHER_MASTER.insert({
   _id : 1005,
   Name : "Ankit",
   Subject : ["PHP","Network"],
   DOB : ISODate("1995-01-07"),
   Gender : "Male",
   City : "Jam Kandola"
})
6
db.TEACHER_MASTER.insert({
   _id : 1006,
   Name : "Roshni",
   Subject : ["ASP.net","Android","Fox-Pro"],
   DOB : ISODate("1998-12-25"),
   Gender : "Female",
   City : "Surat"
})
7
db.TEACHER_MASTER.insert({
   _id : 1007,
   Name : "Surbhi",
   Subject : ["ASP.net","Html"],
   DOB : ISODate("1998-02-26"),
   Gender : "Female",
   City : "Rajkot"
})
8
db.TEACHER_MASTER.insert({
   _id : 1008,
   Name : "Milan",
   Subject : ["Html","ASP.net","Android"],
   DOB : ISODate("1998-12-09"),
   Gender : "Male",
   City : "Rajkot"
})
9
db.TEACHER_MASTER.insert({
   _id : 1009,
   Name : "Radhika",
   Subject : ["Html","ASP.Net","Fox-Pro"],
   DOB : ISODate("1998-02-26"),
   Gender : "Female",
   City : "Rajkot"
})
10
db.TEACHER_MASTER.insert({
   _id : 1010,
   Name : "Priayal",
   Subject : ["Html","ASP.net","Laravel"],
   DOB : ISODate("1998-02-26"),
   Gender : "Female",
   City : "Rajkot"
})


Implement the following SQL Queries.
Implements :-


No
Implement Documents
Queries
1
Display all the teachers on screen.
db.TEACHER_MASTER.find()
2
Display all the teachers with name, subject and gender on screen.
db.TEACHER_MASTER.find({},
   {   
       "_id":0,
       "Name":1,
       "Subject":1,
       "Gender":1,
   }).pretty()
3
Display only those documents where the gender of the teacher is Male.
db.TEACHER_MASTER.find(
{
"Gender":"Male"
},{}).pretty()
4
Update all those documents where Name of teacher is “Ankit" with the new value of Subject as "Java".
db.TEACHER_MASTER.update(
{
   Name:"Ankit"
},{
   $addToSet:{
       Subject:"Java"
   }
})
5
Sort the documents in the given collection by Name in Descending Order.
db.TEACHER_MASTER.find().sort({
   Name:1
})
6
Delete data of all those Teachers who were born after 1st January 1980.
db.TEACHER_MASTER.deleteMany({
   DOB : {
       $gte : new Date("1996-01-01")
   }},{})
7
Count all teachers who are taking Big Data.
db.TEACHER_MASTER.find({
   Subject:'BigData'},{}).count()
8
Display 2nd last record of teacher.
db.TEACHER_MASTER.find().skip(
   db.TEACHER_MASTER.count()-2
   ).limit(1)
9
Delete all teachers who are taking “Fox-Pro".
db.TEACHER_MASTER.deleteMany({
Subject:"Fox-Pro"},{})
10
Update city of teacher with “Ahmedabad” who are living in “Baroda”.
db.TEACHER_MASTER.updateMany(
{City:"Baroda"},
{$set:
{City:"“Ahmedabad"}
}
)


No comments:

Post a Comment