-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmongodb.html
More file actions
377 lines (331 loc) · 11.6 KB
/
mongodb.html
File metadata and controls
377 lines (331 loc) · 11.6 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MongoDB Tutorial</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
/* General Styles */
body {
font-family: 'Arial', sans-serif;
background: #f4f4f4;
margin: 0;
padding: 0;
transition: 0.3s;
}
.dark-mode {
background: #222;
color: #fff;
}
/* Header */
header {
background: #2c3e50;
color: #fff;
padding: 10px 20px;
display: flex;
justify-content: space-between;
align-items: center;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.logo {
font-size: 24px;
font-weight: bold;
color: #fff;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
align-items: center;
}
nav ul li {
margin-left: 25px;
}
nav ul li a {
color: #fff;
text-decoration: none;
font-weight: bold;
font-size: 16px;
transition: color 0.3s ease;
}
nav ul li a:hover {
color: #ff6f61;
}
.hamburger {
display: none;
font-size: 24px;
cursor: pointer;
}
/* Main Content */
.container {
max-width: 900px;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.dark-mode .container {
background: #333;
box-shadow: 0 4px 8px rgba(255, 255, 255, 0.2);
}
h1 {
text-align: center;
color: #007bff;
}
.search-box {
padding: 10px;
width: 80%;
max-width: 400px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
margin: 20px auto;
display: block;
}
.toggle-btn {
background: #008CBA;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
margin: 10px auto;
display: block;
transition: background 0.3s ease;
}
.toggle-btn:hover {
background: #005f73;
}
/* Sections */
.section {
background: #f9f9f9;
padding: 15px;
margin: 10px 0;
border-radius: 10px;
cursor: pointer;
border-left: 5px solid #007bff;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.section:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.content {
display: none;
padding: 15px;
background: #fff;
border-left: 5px solid #007bff;
color: black;
margin: 10px 0;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.dark-mode .content {
background: #444;
color: white;
border-left: 5px solid #008CBA;
}
pre {
background: #1e1e1e;
color: lime;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
position: relative;
}
.copy-btn {
position: absolute;
top: 10px;
right: 10px;
background: #007bff;
color: white;
border: none;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
transition: background 0.3s ease;
}
.copy-btn:hover {
background: #0056b3;
}
textarea {
width: 100%;
height: 100px;
font-family: monospace;
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 14px;
}
.run-btn {
background: #28a745;
color: white;
padding: 8px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-right: 10px;
transition: background 0.3s ease;
}
.run-btn:hover {
background: #218838;
}
a {
display: block;
text-align: center;
margin-top: 20px;
padding: 10px;
color: white;
text-decoration: none;
border-radius: 5px;
transition: background 0.3s ease;
}
a:hover {
background: #0056b3;
}
/* Footer */
footer {
background: #1a252f;
color: #fff;
text-align: center;
padding: 20px;
margin-top: 20px;
}
footer p {
margin: 0;
}
/* Responsive Design */
@media (max-width: 768px) {
.hamburger {
display: block;
}
nav ul {
display: none;
flex-direction: column;
width: 100%;
background: #2c3e50;
position: absolute;
top: 60px;
left: 0;
}
nav ul.active {
display: flex;
}
nav ul li {
margin: 10px 0;
text-align: center;
}
.header h3 {
font-size: 24px;
}
.search-box {
width: 90%;
}
}
</style>
</head>
<body>
<!-- Header -->
<header>
<div class="logo">Learn Coding</div>
<nav>
<ul class="menu">
<li><a href="index.html">Home</a></li>
<li><a href="javascript_tutorial.html">JavaScript Tutorial</a></li>
<li><a href="node_tutorial.html">Node.js Tutorial</a></li>
<li><a href="html_tutorial.html">HTML Tutorial</a></li>
<li><a href="#tutorials">Tutorials</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div class="hamburger" onclick="toggleMenu()">☰</div>
</nav>
</header>
<!-- Main Content -->
<div class="container">
<h1>📌 MongoDB Tutorial - Questions & Answers</h1>
<input type="text" id="search" class="search-box" placeholder="🔍 Search topics..." onkeyup="searchTopics()">
<button class="toggle-btn" onclick="toggleDarkMode()">🌙 Toggle Dark Mode</button>
<!-- Sections -->
<div id="topics-container">
<!-- Questions will be dynamically added here -->
</div>
<a href="index.html">⬅️ Back to Home</a>
</div>
<!-- Footer -->
<footer id="contact">
<p>© 2023 Learn Coding. All rights reserved.</p>
</footer>
<script>
const topics = [
["What is MongoDB?", "MongoDB is a **NoSQL database** that stores data in flexible, JSON-like documents."],
["What are Collections in MongoDB?", "Collections are groups of MongoDB documents, similar to tables in relational databases."],
["What is a Document in MongoDB?", "A document is a set of key-value pairs, stored in BSON (Binary JSON) format."],
["How to Install MongoDB?", "Download MongoDB from the official website and follow the installation instructions for your OS."],
["How to Connect to MongoDB?", "Use the `mongosh` command or a MongoDB driver (e.g., Node.js, Python) to connect to the database."],
["What is the Difference Between MongoDB and SQL?", "MongoDB is a NoSQL database that uses documents, while SQL databases use tables and rows."],
["How to Create a Database in MongoDB?", "Use the `use` command to create or switch to a database."],
["How to Insert Data in MongoDB?", "Use the `insertOne()` or `insertMany()` methods to add documents to a collection."],
["How to Query Data in MongoDB?", "Use the `find()` method to query documents in a collection."],
["What is Indexing in MongoDB?", "Indexing improves query performance by creating indexes on fields."],
["How to Update Data in MongoDB?", "Use the `updateOne()` or `updateMany()` methods to modify documents."],
["How to Delete Data in MongoDB?", "Use the `deleteOne()` or `deleteMany()` methods to remove documents."],
["What is Aggregation in MongoDB?", "Aggregation processes data records and returns computed results."],
["What is Sharding in MongoDB?", "Sharding distributes data across multiple servers to handle large datasets."],
["What is Replication in MongoDB?", "Replication ensures high availability by maintaining multiple copies of data."]
];
const topicsContainer = document.getElementById('topics-container');
topics.forEach((topic, index) => {
topicsContainer.innerHTML += `
<div class="section" onclick="toggleContent('q${index + 1}')">
<h2>${index + 1}️⃣ ${topic[0]}</h2>
</div>
<div id="q${index + 1}" class="content">
<p>${topic[1]}</p>
<textarea id="code${index + 1}">${topic[1]}</textarea><br>
<button class="run-btn" onclick="runCode('code${index + 1}')">Run</button>
<button class="copy-btn" onclick="copyToClipboard('code${index + 1}')">Copy</button>
</div>
`;
});
function toggleContent(id) {
let content = document.getElementById(id);
content.style.display = (content.style.display === "none" || content.style.display === "") ? "block" : "none";
}
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
Swal.fire("🌙 Dark mode " + (document.body.classList.contains("dark-mode") ? "enabled" : "disabled"));
}
function searchTopics() {
let input = document.getElementById("search").value.toLowerCase();
let sections = document.getElementsByClassName("section");
for (let section of sections) {
if (section.textContent.toLowerCase().includes(input)) section.style.display = "";
else section.style.display = "none";
}
}
function copyToClipboard(codeId) {
let codeElement = document.getElementById(codeId);
codeElement.select();
document.execCommand("copy");
Swal.fire("✅ Code copied!");
}
function runCode(codeId) {
let code = document.getElementById(codeId).value;
try { eval(code); }
catch (error) { Swal.fire("❌ Error: " + error.message); }
}
function toggleMenu() {
const menu = document.querySelector('.menu');
menu.classList.toggle('active');
}
</script>
</body>
</html>