-
Notifications
You must be signed in to change notification settings - Fork 0
/
12-mongodb-atlas.qmd
363 lines (255 loc) · 11.2 KB
/
12-mongodb-atlas.qmd
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
---
title: "MongoDB Atlas:<br>The Developer Data Platform"
block-headings: TRUE
author: "<br/><br/><br/>Alfa Nugraha Pradana"
institute: "Prodi Statistika dan Sains Data IPB University"
footer: "[rpubs.com/alfanugraha/sta1562-p12](https://rpubs.com/alfanugraha/sta1562-p12) "
format:
revealjs:
theme: [default, style.scss]
slide-number: c/t
code-copy: true
# center-title-slide: false
code-overflow: wrap
highlight-style: a11y
height: 1080
width: 1920
logo: assets/img/LogoIPBUni.png
preview-links: auto
editor: source
---
## Outline
<br/>
- Insert, Update, Delete Documents
- Query
- Atlas
- Twitter for Developer
- GitHub Actions
## `insertMany()`
Membuat koleksi `cities`
```{{json}}
db.createCollection('cities')
```
<br>
Bulk insert
```{{json}}
db.cities.insertMany([
{"name": "Seoul", "country": "South Korea", "continent": "Asia", "population": 25.674 },
{"name": "Mumbai", "country": "India", "continent": "Asia", "population": 19.980 },
{"name": "Lagos", "country": "Nigeria", "continent": "Africa", "population": 13.463 },
{"name": "Beijing", "country": "China", "continent": "Asia", "population": 19.618 },
{"name": "Shanghai", "country": "China", "continent": "Asia", "population": 25.582 },
{"name": "Osaka", "country": "Japan", "continent": "Asia", "population": 19.281 },
{"name": "Cairo", "country": "Egypt", "continent": "Africa", "population": 20.076 },
{"name": "Tokyo", "country": "Japan", "continent": "Asia", "population": 37.400 },
{"name": "Karachi", "country": "Pakistan", "continent": "Asia", "population": 15.400 },
{"name": "Dhaka", "country": "Bangladesh", "continent": "Asia", "population": 19.578 },
{"name": "Rio de Janeiro", "country": "Brazil", "continent": "South America", "population": 13.293 },
{"name": "São Paulo", "country": "Brazil", "continent": "South America", "population": 21.650 },
{"name": "Mexico City", "country": "Mexico", "continent": "North America", "population": 21.581 },
{"name": "Delhi", "country": "India", "continent": "Asia", "population": 28.514 },
{"name": "Buenos Aires", "country": "Argentina", "continent": "South America", "population": 14.967 },
{"name": "Kolkata", "country": "India", "continent": "Asia", "population": 14.681 },
{"name": "New York", "country": "United States", "continent": "North America", "population": 18.819 },
{"name": "Manila", "country": "Philippines", "continent": "Asia", "population": 13.482 },
{"name": "Chongqing", "country": "China", "continent": "Asia", "population": 14.838 },
{"name": "Istanbul", "country": "Turkey", "continent": "Europe", "population": 14.751 }
])
```
## Insert, Update, Delete Documents
<br>
Membuat dokumen baru ke dalam koleksi MongoDB
```{{json}}
db.cities.insertOne({'_id' : 1, 'name':'Jakarta', 'country': 'Indonesia', 'continent': 'Asia', 'population': 10.56})
```
<br>
Mengupdate dokumen
```{{json}}
db.cities.updateOne({'_id' : 1}, { $set: {'name':'Bandung', 'population': 2.5}})
```
<br>
Menghapus dokumen
```{{json}}
db.cities.deleteOne({'_id':1})
```
## Comparison Query Operators {.scrollable}
<br>
Beberapa contoh operator yang bisa digunakan:
- `$gt` :
```{{json}}
db.cities.find({ population: { $gt: 25 } })
```
- `$lt` :
```{{json}}
db.cities.find({ population: { $lt: 14 } })
```
- `$in` :
```{{json}}
db.cities.find({ continent: { $in: ["Asia", "Africa"] }, population: {$lt: 15 } })
```
<br>
+-----------+-------------------------------------------------------------------------+
| Operator | Keterangan |
+===========+=========================================================================+
| `$eq` | Membandingkan nilai yang sama dengan nilai lainnya. |
+-----------+-------------------------------------------------------------------------+
| `$ne` | Membandingkan nilai yang tidak sama dengan nilai lainnya. |
+-----------+-------------------------------------------------------------------------+
| `$gt` | Membandingkan nilai yang lebih besar dari nilai lainnya. |
+-----------+-------------------------------------------------------------------------+
| `$gte` | Membandingkan nilai yang lebih besar atau sama dengan nilai lainnya. |
+-----------+-------------------------------------------------------------------------+
| `$lt` | Membandingkan nilai yang lebih kecil dari nilai lainnya. |
+-----------+-------------------------------------------------------------------------+
| `$lte` | Membandingkan nilai yang lebih kecil atau sama dengan nilai lainnya |
+-----------+-------------------------------------------------------------------------+
| `$in` | Membandingkan nilai dengan nilai yang ada di array. |
+-----------+-------------------------------------------------------------------------+
| `$nin` | Membandingkan nilai yang tidak ada dalam nilai yang ada di array. |
+-----------+-------------------------------------------------------------------------+
<br>
## Logical Query Operators {.scrollable}
<br>
Beberapa contoh operator yang bisa digunakan:
- `$and` :
```{{json}}
db.cities.find({
$and: [{
continent: { $in: ["South America", "North America"] },
population: { $gt: 20 }
}]
})
```
- `$not` :
```{{json}}
db.cities.find({
continent: {
$not : { $in: ["Asia", "South America", "North America"] }
}
})
```
<br>
+-----------+-------------------------------------------------------------------------+
| Operator | Keterangan |
+===========+=========================================================================+
| `$and` | Menggabungkan query dengan operasi AND |
+-----------+-------------------------------------------------------------------------+
| `$or` | Menggabungkan query dengan operasi OR |
+-----------+-------------------------------------------------------------------------+
| `$nor` | Menggabungkan query dengan operasi NOR |
+-----------+-------------------------------------------------------------------------+
| `$not` | Membalikkan kondisi, mengembalikan documen yang tidak sesuai kondisi |
+-----------+-------------------------------------------------------------------------+
<br>
## Element Query Operators {.scrollable}
<br>
- `$exists` :
```{{json}}
db.cities.find({
continent: {
$exists : false
}
})
```
- `$type` :
```{{json}}
db.cities.find({
population: {$type: ['double'] }
})
```
<br>
+-----------+-------------------------------------------------------------------------+
| Operator | Keterangan |
+===========+=========================================================================+
| `$exists` | Mencocokkan dokumen yang memiliki field tersebut |
+-----------+-------------------------------------------------------------------------+
| `$type` | Mencocokkan dokumen yang memiliki type field tersebut |
+-----------+-------------------------------------------------------------------------+
<br>
## Evaluation Query Operators {.scrollable}
<br>
- `$expr` :
```{{json}}
db.cities.find({
$expr : {
$gt : ["population", 25]
}
})
```
<br>
+---------------+-------------------------------------------------------------------------+
| Operator | Keterangan |
+===============+=========================================================================+
| `$expr` | Menggunakan aggregation operation |
+---------------+-------------------------------------------------------------------------+
| `$jsonSchema` | Validasi document sesuai dengan JSON schema |
+---------------+-------------------------------------------------------------------------+
| `$mod` | Melakukan operasi modulo |
+---------------+-------------------------------------------------------------------------+
| `$regex` | Mengambil document sesuai dengan regular expression (PCRE) |
+---------------+-------------------------------------------------------------------------+
| `$text` | Melakukan pencarian menggunakan text |
+---------------+-------------------------------------------------------------------------+
| `$where` | Mengambil document dengan JavaScript Function |
+---------------+-------------------------------------------------------------------------+
<br>
## Query Modifier Function {.scrollable}
<br>
- `count()` :
```{{json}}
db.cities.find({}).count()
```
<br>
```{{json}}
db.cities.find({continent: "Asia"}).count()
```
<br>
+---------------+-------------------------------------------------------------------------+
| Fungsi | Keterangan |
+===============+=========================================================================+
| `count()` | Mengambil jumlah data hasil query |
+---------------+-------------------------------------------------------------------------+
| `limit(size)` | Membatasi jumlah data yang didapat dari query |
+---------------+-------------------------------------------------------------------------+
| `skip(size)` | Menghiraukan data pertama hasil query sejumlah yang ditentukan |
+---------------+-------------------------------------------------------------------------+
| `sort(query)` | Mengurutkan hasil data query |
+---------------+-------------------------------------------------------------------------+
<br>
## Atlas
> Teknologi multi-cloud MongoDB sebagai platform pengembang data
<br>
Atlas tidak hanya bekerja sebagai DaaS (Database as a Service) pada umumnya. Atlas adalah sebuah platform lengkap bagi data developer. Berikut ini ada keunggulan dan fitur dari Atlas:
::: columns
::: {.column .fragment width="50%"}
- Backups with point-in-time restore
- Online Archive
- Operational insights
- CLI and administration API
:::
::: {.column .fragment width="50%"}
- Atlas Search
- Atlas Device Sync
- Atlas Data Lake
- Atlas Data Federation
- Atlas Chart
- Atlas App Services
:::
:::
## Setting up
1. Register **MongoDB Atlas**:
<https://www.mongodb.com/cloud/atlas/register>
2. Deploy Atlas Cluster
3. Pengaturan user database dan alamat IP agar dapat diakses
4. Penggunaan Atlas Data Explorer
## Atlas Cluster Dashboard
![](assets/img/atlas-home.png){fig-align="center" width="1000"}
## Mengakses Atlas
![](assets/img/atlas-access.png){fig-align="center" width="1000"}
## Atlas Database
![](assets/img/atlas-db.png){fig-align="center" width="1000"}
## Twitter for Developer
![](assets/img/twitdev.png){fig-align="center" width="1000"}
## GitHub Actions
![](assets/img/git-action.png){fig-align="center" width="1000"}
# Pertanyaan? {background="#43464B"}