-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27_02_2025.sql
133 lines (125 loc) Β· 2.59 KB
/
27_02_2025.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
129
130
131
132
133
// Working with TechStore database
use TechStoreDB
switched to db TechStoreDB
// Create Electronics collection
db.createCollection("Electronics")
{ ok: 1 }
// Insert product records (corrected "spec" field name)
db.Electronics.insertMany([
{
"_id": 101,
"productName": "GalaxyPhone",
"price": 799,
"releaseDate": ISODate("2011-05-14"),
"specs": {
"ram": 4,
"screenSize": 6.5,
"cpu": 2.66
},
"colors": ["white", "black"],
"storageOptions": [64, 128, 256]
},
{
"_id": 102,
"productName": "GalaxyTab",
"price": 899,
"releaseDate": ISODate("2011-09-01"),
"specs": {
"ram": 16,
"screenSize": 9.5,
"cpu": 2.66
},
"colors": ["white", "black", "purple"],
"storageOptions": [128, 256, 512]
}
])
{
acknowledged: true,
insertedIds: { '0': 101, '1': 102 }
}
// View all electronics products
db.Electronics.find().pretty()
{
"_id": 101,
"productName": "GalaxyPhone",
"price": 799,
"releaseDate": ISODate("2011-05-14T00:00:00Z"),
"specs": {
"ram": 4,
"screenSize": 6.5,
"cpu": 2.66
},
"colors": ["white", "black"],
"storageOptions": [64, 128, 256]
}
{
"_id": 102,
"productName": "GalaxyTab",
"price": 899,
"releaseDate": ISODate("2011-09-01T00:00:00Z"),
"specs": {
"ram": 16,
"screenSize": 9.5,
"cpu": 2.66
},
"colors": ["white", "black", "purple"],
"storageOptions": [128, 256, 512]
}
// Create TechBooks collection
db.createCollection("TechBooks")
{ ok: 1 }
// Insert book records with corrected structure
db.TechBooks.insertMany([
{
"_id": 201,
"title": "Modern Android Development",
"isbn": "9781933988673",
"categories": ["Mobile", "Programming"],
"available": true
},
{
"_id": 202,
"title": "JavaScript Frameworks Guide",
"isbn": "9781935182722",
"categories": ["Web Development"],
"available": true
}
])
{
acknowledged: true,
insertedIds: { '0': 201, '1': 202 }
}
// Find available books
db.TechBooks.find({ available: true }).pretty()
{
"_id": 201,
"title": "Modern Android Development",
"isbn": "9781933988673",
"categories": ["Mobile", "Programming"],
"available": true
}
{
"_id": 202,
"title": "JavaScript Frameworks Guide",
"isbn": "9781935182722",
"categories": ["Web Development"],
"available": true
}
// Projection examples
db.Electronics.findOne(
{ "_id": 101 },
{ "productName": 1, "price": 1, "specs.screenSize": 1 }
)
{
"_id": 101,
"productName": "GalaxyPhone",
"price": 799,
"specs": {
"screenSize": 6.5
}
}
// Cleanup collections
db.Electronics.drop()
true
db.TechBooks.drop()
true