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/bin/cli.js +10 -0
- package/data/aiop.txt +105 -26
- package/data/bdh.txt +105 -55
- package/data/div.txt +134 -67
- package/data/mlf.txt +225 -119
- package/data/rpa.txt +279 -0
- package/package.json +1 -1
package/data/div.txt
CHANGED
|
@@ -1,83 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
--------------------------------------------------------------------------------
|