-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodbassignment1.sql
128 lines (95 loc) · 4.07 KB
/
mongodbassignment1.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
student@student-OptiPlex-3020:~/mongodb-linux-x86_64-2.6.3/bin$ ./mongo 10.10.12.108/t31232db -u
t31232 -p
MongoDB shell version: 2.6.3
Enter password:
connecting to: 10.10.12.108/t31232db
> use 31232DB
switched to db 31232DB
> db.createCollection("Employee")
{ "ok" : 1 }
> show collections
Employee
system.indexes
> db.Employee.insert({"empID" :101 , "Company": "Apple","Designation": "Service Analyst"})
WriteResult({ "nInserted" : 1 })
> db.Employee.insert({"empID" :102 , "Company": "Google","Designation": "Driver System Analyst"})
WriteResult({ "nInserted" : 1 })
> db.Employee.insert({"empID" :103 , "Company": "Apple","Designation": "Software Engineer"})
WriteResult({ "nInserted" : 1 })
> db.Employee.insert({"empID" :104 , "Company": "Google","Designation": "SDE 2"})
WriteResult({ "nInserted" : 1 })
> db.Employee.insert({"empID" :105 , "Company": "Tesla","Designation": "UI Designer"})
WriteResult({ "nInserted" : 1 })
> db.Employee.find()
{ "_id" : ObjectId("63478b92eaf2f2a7aa7b00d6"), "empID" : 101, "Company" : "Apple", "Designation" :
"Service Analyst" }
{ "_id" : ObjectId("63478baeeaf2f2a7aa7b00d7"), "empID" : 102, "Company" : "Google", "Designation"
: "Driver System Analyst" }
{ "_id" : ObjectId("63478be5eaf2f2a7aa7b00d8"), "empID" : 103, "Company" : "Apple", "Designation" :
"Software Engineer" }
{ "_id" : ObjectId("63478c0feaf2f2a7aa7b00d9"), "empID" : 104, "Company" : "Google", "Designation" :
"SDE 2" }
{ "_id" : ObjectId("63478c28eaf2f2a7aa7b00da"), "empID" : 105, "Company" : "Tesla", "Designation" :
"UI Designer" }
> db.Employee.find({"empID":104})
{ "_id" : ObjectId("63478c0feaf2f2a7aa7b00d9"), "empID" : 104, "Company" : "Google", "Designation" :
"SDE 2" }
> db.Employee.update({"Designation": "SDE 2"}, {$set:{"Designation": "CEO"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.Employee.find()
{ "_id" : ObjectId("63478b92eaf2f2a7aa7b00d6"), "empID" : 101, "Company" : "Apple", "Designation" :
"Service Analyst" }
{ "_id" : ObjectId("63478baeeaf2f2a7aa7b00d7"), "empID" : 102, "Company" : "Google", "Designation"
: "Driver System Analyst" }
{ "_id" : ObjectId("63478be5eaf2f2a7aa7b00d8"), "empID" : 103, "Company" : "Apple", "Designation" :
"Software Engineer" }
{ "_id" : ObjectId("63478c0feaf2f2a7aa7b00d9"), "empID" : 104, "Company" : "Google", "Designation" :
"CEO" }
{ "_id" : ObjectId("63478c28eaf2f2a7aa7b00da"), "empID" : 105, "Company" : "Tesla", "Designation" :
"UI Designer" }
> db.Employee.remove({"Company": "Tesla"})
WriteResult({ "nRemoved" : 1 })
> db.Employee.find()
{ "_id" : ObjectId("63478b92eaf2f2a7aa7b00d6"), "empID" : 101, "Company" : "Apple", "Designation" :
"Service Analyst" }
{ "_id" : ObjectId("63478baeeaf2f2a7aa7b00d7"), "empID" : 102, "Company" : "Google", "Designation"
: "Driver System Analyst" }
{ "_id" : ObjectId("63478be5eaf2f2a7aa7b00d8"), "empID" : 103, "Company" : "Apple", "Designation" :
"Software Engineer" }
{ "_id" : ObjectId("63478c0feaf2f2a7aa7b00d9"), "empID" : 104, "Company" : "Google", "Designation" :
"CEO" }
> db.Employee.find().pretty()
{
"_id" : ObjectId("63478b92eaf2f2a7aa7b00d6"),
"empID" : 101,
"Company" : "Apple",
"Designation" : "Service Analyst"
}
{
"_id" : ObjectId("63478baeeaf2f2a7aa7b00d7"),
"empID" : 102,
"Company" : "Google",
"Designation" : "Driver System Analyst"
}
{
"_id" : ObjectId("63478be5eaf2f2a7aa7b00d8"),
"empID" : 103,
"Company" : "Apple",
"Designation" : "Software Engineer"
}
{
"_id" : ObjectId("63478c0feaf2f2a7aa7b00d9"),
"empID" : 104,
"Company" : "Google",
"Designation" : "CEO"
}
> db.Employee.find({"Company":{$in : ["Google","ABC"]}})
{ "_id" : ObjectId("63478baeeaf2f2a7aa7b00d7"), "empID" : 102, "Company" : "Google", "Designation"
: "Driver System Analyst" }
{ "_id" : ObjectId("63478c0feaf2f2a7aa7b00d9"), "empID" : 104, "Company" : "Google", "Designation" :
"CEO" }
> db.Employee.find( { "Company": "Apple", "empID": { $lt: 104 } } )
{ "_id" : ObjectId("63478b92eaf2f2a7aa7b00d6"), "empID" : 101, "Company" : "Apple", "Designation" :
"Service Analyst" }
{ "_id" : ObjectId("63478be5eaf2f2a7aa7b00d8"), "empID" : 103, "Company" : "Apple", "Designation" :
"Software Engineer" }