exam-sub 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/data/div.txt CHANGED
@@ -1,83 +1,150 @@
1
- MongoDB CRUD Operations – CollegeDB
2
- Complete practical code for Questions 1–3 using one MongoDB database with separate collections: employees,
3
- students, and books.
4
- Complete Code
5
- // Create / Select Database
1
+ ================================================================================
2
+ MONGODB CRUD OPERATIONS – COLLEGE DB
3
+ ================================================================================
4
+
5
+ AIM:
6
+ To implement CRUD (Create, Read, Update, Delete) operations using MongoDB
7
+ queries across three collections: employees, students, and books inside a single
8
+ database named collegeDB.
9
+
10
+
11
+ ================================================================================
12
+ OPTIONAL: RESET / CLEAN RUN COMMANDS
13
+ ================================================================================
14
+
15
+ NOTE:
16
+ If you run the practical multiple times, existing collections and data may cause
17
+ duplicate records or collection-exists errors. Use the following commands first
18
+ when you want a clean start.
19
+
20
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
21
+ --------------------------------------------------------------------------------
22
+ // Select Database
6
23
  use collegeDB
7
- // ==========================================
8
- // Q1: EMPLOYEES
9
- // ==========================================
10
- // Create Collection
24
+
25
+ // Drop Existing Collections
26
+ db.employees.drop()
27
+ db.students.drop()
28
+ db.books.drop()
29
+ --------------------------------------------------------------------------------
30
+
31
+
32
+ ================================================================================
33
+ Q1: EMPLOYEES COLLECTION
34
+ ================================================================================
35
+
36
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
37
+ --------------------------------------------------------------------------------
38
+ // Select Database
39
+ use collegeDB
40
+
41
+ // Step 1: Create Collection
11
42
  db.createCollection("employees")
12
- // Insert Values
43
+
44
+ // Step 2: Insert Multiple Documents
13
45
  db.employees.insertMany([
14
- {name:"Alice", position:"Manager", salary:70000},
15
- {name:"Bob", position:"Developer", salary:55000},
16
- {name:"Charlie", position:"HR", salary:45000}
46
+ { name: "Alice", position: "Manager", salary: 70000 },
47
+ { name: "Bob", position: "Developer", salary: 55000 },
48
+ { name: "Charlie", position: "HR", salary: 45000 }
17
49
  ])
18
- // Read - Salary greater than 50000
19
- db.employees.find({salary:{$gt:50000}})
20
- // Update - Increase Developer salary by 10%
50
+
51
+ // Step 3: Read - Retrieve employees with salary greater than 50,000
52
+ db.employees.find({ salary: { $gt: 50000 } })
53
+
54
+ // Step 4: Update - Increase Developer salary by 10%
21
55
  db.employees.updateMany(
22
- {position:"Developer"},
23
- {$mul:{salary:1.10}}
56
+ { position: "Developer" },
57
+ { $mul: { salary: 1.10 } }
24
58
  )
25
- // Delete - Remove Charlie
26
- db.employees.deleteOne({name:"Charlie"})
27
- // ==========================================
28
- // Q2: STUDENTS
29
- // ==========================================
30
- // Create Collection
59
+
60
+ // Step 5: Delete - Remove employee named Charlie
61
+ db.employees.deleteOne({ name: "Charlie" })
62
+ --------------------------------------------------------------------------------
63
+
64
+
65
+ ================================================================================
66
+ Q2: STUDENTS COLLECTION
67
+ ================================================================================
68
+
69
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
70
+ --------------------------------------------------------------------------------
71
+ // Select Database
72
+ use collegeDB
73
+
74
+ // Step 1: Create Collection
31
75
  db.createCollection("students")
32
- // Insert Values
76
+
77
+ // Step 2: Insert Single Document
33
78
  db.students.insertOne({
34
- name:"John Doe",
35
- age:22,
36
- course:"Computer Science"
79
+ name: "John Doe",
80
+ age: 22,
81
+ course: "Computer Science"
37
82
  })
38
- // Read - Age greater than 20
39
- db.students.find({age:{$gt:20}})
40
- // Update - Change course
83
+
84
+ // Step 3: Read - Retrieve students with age greater than 20
85
+ db.students.find({ age: { $gt: 20 } })
86
+
87
+ // Step 4: Update - Change course to Data Science
41
88
  db.students.updateOne(
42
- {name:"John Doe"},
43
- {$set:{course:"Data Science"}}
89
+ { name: "John Doe" },
90
+ { $set: { course: "Data Science" } }
44
91
  )
45
- // Delete - Age less than 21
46
- db.students.deleteMany({age:{$lt:21}})
47
- // ==========================================
48
- // Q3: BOOKS
49
- // ==========================================
50
- // Create Collection
92
+
93
+ // Step 5: Delete - Remove students with age less than 21
94
+ db.students.deleteMany({ age: { $lt: 21 } })
95
+ --------------------------------------------------------------------------------
96
+
97
+
98
+ ================================================================================
99
+ Q3: BOOKS COLLECTION
100
+ ================================================================================
101
+
102
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
103
+ --------------------------------------------------------------------------------
104
+ // Select Database
105
+ use collegeDB
106
+
107
+ // Step 1: Create Collection
51
108
  db.createCollection("books")
52
- // Insert Values
109
+
110
+ // Step 2: Insert Single Document
53
111
  db.books.insertOne({
54
- title:"The Alchemist",
55
- author:"Paulo Coelho",
56
- publishedYear:1988,
57
- copiesSold:65000000
112
+ title: "The Alchemist",
113
+ author: "Paulo Coelho",
114
+ publishedYear: 1988,
115
+ copiesSold: 65000000
58
116
  })
59
- // Read - Books published before 2000
60
- db.books.find({publishedYear:{$lt:2000}})
61
- // Update - Add rating
117
+
118
+ // Step 3: Read - Retrieve books published before the year 2000
119
+ db.books.find({ publishedYear: { $lt: 2000 } })
120
+
121
+ // Step 4: Update - Add rating field to 'The Alchemist'
62
122
  db.books.updateOne(
63
- {title:"The Alchemist"},
64
- {$set:{rating:4.8}}
123
+ { title: "The Alchemist" },
124
+ { $set: { rating: 4.8 } }
65
125
  )
66
- // Delete - Books with copies sold less than 1 million
67
- db.books.deleteMany({copiesSold:{$lt:1000000}})
68
- Fresh Run / Reset Database Collections
69
- If you run the practical multiple times, existing collections and data may cause duplicate records or collection-exists
70
- errors. Use the following commands first when you want a clean run.
71
- use collegeDB
72
- db.employees.drop()
73
- db.students.drop()
74
- db.books.drop()
75
- Important MongoDB Note
76
- MongoDB does not use tables like MySQL. MongoDB stores data in collections. For this practical, employees,
77
- students, and books are collections inside the same collegeDB database.
78
- CRUD Summary
79
- Create: createCollection(), insertOne(), insertMany()
80
- Read: find()
81
- Update: updateOne(), updateMany()
82
- Delete: deleteOne(), deleteMany()
83
-  
126
+
127
+ // Step 5: Delete - Remove books with copies sold less than 1 million
128
+ db.books.deleteMany({ copiesSold: { $lt: 1000000 } })
129
+ --------------------------------------------------------------------------------
130
+
131
+
132
+ ================================================================================
133
+ IMPORTANT MONGODB CONCEPTS & SUMMARY
134
+ ================================================================================
135
+
136
+ DATABASE CONCEPT:
137
+ MongoDB does not use tables like relational databases (e.g., MySQL). Instead,
138
+ it stores JSON-like documents inside collections. In this practical,
139
+ 'employees', 'students', and 'books' are separate collections stored inside
140
+ the single 'collegeDB' database.
141
+
142
+ CRUD METHOD SUMMARY:
143
+ --------------------------------------------------------------------------------
144
+ Operation | MongoDB Functions / Methods
145
+ --------------------------------------------------------------------------------
146
+ CREATE | createCollection(), insertOne(), insertMany()
147
+ READ | find()
148
+ UPDATE | updateOne(), updateMany()
149
+ DELETE | deleteOne(), deleteMany()
150
+ --------------------------------------------------------------------------------