Penerapan Database MongoDB dengan Visual Studio Code
Penerapan Database MongoDB dengan Visual Studio Code
Project Based Learning
Apa itu MongoDB?
Mengapa MongoDB?
Visualisasi & Filter Data, serta fungsi CRUD data.
Langkah - Langkah :
1. Import file datasheet yang akan dipakai ke MongoDB menggunakkan VS Code. pastikan file sudah csv dan nama sesuai dengan nama file. buat file pada VS Code dengan nama film.cvs
berikut kode untuk impor csv :
2. Untuk menampilkan data dan fungsi CRUD, buat file app.py lalu isi dengan kode seperti dibawah ini :
3. Untuk menampilkan grafik, buat Buatlah folder baru "templates" untuk menyimpan script html, terdapat 3 file yaitu index.html untuk mengatur tampilan halaman awal, edit.html untuk mengatur tampilan halaman edit, dan charts.html untuk mengatur tampilan halaman grafik.
- Kode file index.html :
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Youtube</title><style>table {border-collapse: collapse;width: 100%;}th,td {border: 1px solid black;padding: 8px;text-align: left;max-width: 200px; /* Atur lebar maksimum untuk kolom */overflow: hidden;white-space: nowrap;text-overflow: ellipsis;margin: 4px; /* Menambahkan jarak pada setiap sisi */}th:nth-child(1),td:nth-child(1) {width: 8%; /* Atur lebar kolom work_year di sini */}th:nth-child(2),td:nth-child(2) {width: 8%; /* Atur lebar kolom experience_level di sini */}th:nth-child(3),td:nth-child(3) {width: 8%; /* Atur lebar kolom employment_type di sini */}th:nth-child(4),td:nth-child(4) {width: 16%; /* Atur lebar kolom job_title di sini */}th:nth-child(5),td:nth-child(5) {width: 8%; /* Atur lebar kolom salary di sini */}th:nth-child(6),td:nth-child(6) {width: 12%; /* Atur lebar kolom salary_currency di sini */}th:nth-child(7),td:nth-child(7) {width: 12%; /* Atur lebar kolom salary_in_usd di sini */}th:nth-child(8),td:nth-child(8) {width: 12%; /* Atur lebar kolom employee_residence di sini */}th:nth-child(9),td:nth-child(9) {width: 8%; /* Atur lebar kolom remote_ratio di sini */}th:nth-child(10),td:nth-child(10) {width: 12%; /* Atur lebar kolom company_location di sini */}th:nth-child(11),td:nth-child(11) {width: 8%; /* Atur lebar kolom company_size di sini */}/* Tambahkan margin-bottom untuk memberikan ruang antara form dan tabel */form {margin-bottom: 20px;}</style></head><body><h1>Youtube</h1><p>Data Length: {{ data|length }} </p><a href="/graph"><button type="button">Tampilkan Grafik</button></a></p><form action="/" method="POST"><label for="search">Cari:</label><input type="text" id="search" name="query" /><button type="submit">Cari</button></form><style>form {display: flex;flex-wrap: wrap;}div {flex: 0 0 10%; /* Setiap div akan menempati 30% dari lebar container */margin-right: 5%; /* Menambahkan jarak antara setiap div */margin-bottom: 15px; /* Menambahkan jarak antar baris */}</style><form action="/add" method="POST"><div><label for="Title">Title:</label><input type="text" id="Title" name="Title" /></div><div><label for="VideoID">VideoID:</label><input type="text" id="VideoID" name="VideoID" /></div><div><label for="PublishedAt">PublishedAt:</label><input type="text" id="PublishedAt" name="PublishedAt" /></div><div><label for="Keyword">Keyword:</label><input type="text" id="Keyword" name="Keyword" /></div><div><label for="Likes">Likes:</label><input type="text" id="Likes" name="Likes" /></div><div><label for="Comments">Comments:</label><input type="text" id="Comments" name="Comments" /></div><div><label for="Views">Views:</label><input type="text" id="Views" name="Views" /></div><buttontype="submit"style="width: 150px; height: 25px; margin-top: 15px">Tambah Data</button></form><table><thead><tr><th>Title</th><th>VideoID</th><th>PublishedAt</th><th>Keyword</th><th>Likes</th><th>Comments</th><th>Views</th><th>Aksi</th></tr></thead><tbody>{% for row in data %}<tr><td>{{ row.Title }}</td><td>{{ row.VideoID }}</td><td>{{ row.PublishedAt }}</td><td>{{ row.Keyword }}</td><td>{{ row.Likes }}</td><td>{{ row.Comments }}</td><td>{{ row.Views }}</td><td><form action="/edit/{{ row._id }}" method="GET"><button type="submit">Edit Data</button></form><form action="/delete/{{ row._id }}" method="GET"><button type="submit">Hapus</button></form></td></tr>{% endfor %}</tbody></table></body></html>
- Kode file edit.html
HASIL :
1. Tampilan Awal
Pada halaman awal akan muncul data yang sudah diimport dan jumlah datanya. Di sini juga terdapat tools untuk melakukan pencarian berdasarkan kategori tertentu, tampilkan grafik, tambah data, hapus data, dan edit data pada pojok kanan tabel (aksi).
2. Tampilan edit data
apabila tombol aksi dikil pada edit, maka akan muncul halaman edit data
3. Hasil tampilan cari berdasarkan kategori
apabila ingin melihat data tertentu saja, kita hanya perlu ketikkan sesuai dengan kategorinya, misal ingin melihat data gaji kategori , maka ketik pada pencarian :
- Title : The most Expensive
Untuk menghapus data dapat memilih hapus pada aksi kemudian pada Data Length jumlah data akan berkurang.
Komentar
Posting Komentar