Sei sulla pagina 1di 41

Workshop TI Terapan #8

Mongo DB
Oleh Politeknik Elektronika Negeri Surabaya
2018
2

In Production

http://www.mongodb.org/about/production-deployments/
3

NoSQL

• Key-value

• Graph database

• Document-oriented

• Column family
4

Document store
RDBMS MongoDB
Database Database
Table, View Collection
Row Document (JSON, BSON)
Column Field
Index Index
Join Embedded Document
Foreign Key Reference
Partition Shard
Document store
RDBMS MongoDB
Database Database > db.user.findOne({age:39})
Table, View Collection {
"_id" : ObjectId("5114e0bd42…"),
Row Document (JSON, BSON)
"first" : "John",
Column Field "last" : "Doe",
Index Index "age" : 39,
Join Embedded Document"interests" : [
Foreign Key Reference "Reading",
"Mountain Biking ]
Partition Shard
"favorites": {
"color": "Blue",
"sport": "Soccer"}
} 5
6

CRUD
• Create
• db.collection.insert( <document> )
• db.collection.save( <document> )
• db.collection.update( <query>, <update>, { upsert: true } )
• Read
• db.collection.find( <query>, <projection> )
• db.collection.findOne( <query>, <projection> )
• Update
• db.collection.update( <query>, <update>, <options> )
• Delete
• db.collection.remove( <query>, <justOne> )
7

CRUD example
> db.user.find ()
> db.user.insert({ {
first: "John", "_id" : ObjectId("51…"),
last : "Doe", "first" : "John",
age: 39 "last" : "Doe",
}) "age" : 39
}

> db.user.update(
{"_id" : ObjectId("51…")},
{ > db.user.remove({
$set: {
"first": /^J/
age: 40,
salary: 7000} })
}
)
8

Features
• Penyimpanan Berorientasi
Dokumen
• Dukungan Indeks Penuh
Agile
• Replikasi & Ketersediaan
Tinggi
• Auto-Sharding
• Querying Scalable
• Pembaruan Cepat Di Tempat
• Peta / Reduce
9

Memory Mapped Files


• „File yang dipetakan-memori adalah segmen memori virtual yang
telah diberi korelasi byte-untuk-byte langsung dengan beberapa
bagian dari file atau file-seperti sumber daya.”1
• mmap()

1: http://en.wikipedia.org/wiki/Memory-mapped_file
10

Kumpulan Replika Host1:10000

• Redundansi dan Failover Host2:10001

• Zero downtime untuk Host3:10002


upgrade dan pemeliharaan replica1

• Master-slave replication
Client
• Konsistensi Kuat
• Konsistensi Tertunda

• Fitur geospasial
11

Sharding
• Memartisi data Anda
• Skala menulis
throughput
• Tingkatkan kapasitas
• Penyeimbangan
otomatis
shard1 shard2
Host1:10000 Host2:10010

configdb
Host3:20000

Host4:30000 Client
12

Mixed
shard1

...
Host1:10000
shardn
Host2:10001 Host4:10010

Host3:10002
replica1

configdb
Host5:20000

Host6:30000 Client

Host7:30000
13

Map/Reduce
db.collection.mapReduce(
<mapfunction>,
<reducefunction>,
{
out: <collection>,
query: <>,
sort: <>,
limit: <number>,
finalize: <function>,
scope: <>,
jsMode: <boolean>,
verbose: <boolean>
}
)
var mapFunction1 = function() { emit(this.cust_id, this.price); };
var reduceFunction1 = function(keyCustId, valuesPrices)
{ return sum(valuesPrices); };
14

Fitur lainnya
• Mudah dipasang dan digunakan
• Dokumentasi rinci
• Berbagai API
• JavaScript, Python, Ruby, Perl, Java, Java, Scala, C #, C ++, Haskell, Erlang
• Community
• Open source
15

Theory of noSQL: CAP


• Banyak node C
• Node berisi replika dari partisi
data
• Konsistensi
• semua replika mengandung versi
data yang sama
• Tersedianya
• sistem tetap beroperasi pada node
yang gagal A P
• Partisi tolarence
• beberapa titik masuk
• sistem tetap beroperasi pada
CAP Theorem:
pemisahan sistem satisfying all three at the
same time is impossible
16

Theory of noSQL: CAP


• Banyak node C
• Node berisi replika dari partisi
data
• Konsistensi
• semua replika mengandung versi
data yang sama
• Tersedianya
• sistem tetap beroperasi pada node
yang gagal A P
• Partisi tolarence
• beberapa titik masuk
• sistem tetap beroperasi pada
CAP Theorem:
pemisahan sistem satisfying all three at the
same time is impossible
17

ACID - BASE

• Basically
• Atomicity Available (CP)
• Consistency • Soft-state
• Isolation • Eventually
• Durability consistent (AP)

Pritchett, D.: BASE: An Acid Alternative (queue.acm.org/detail.cfm?id=1394128)


Agenda
• Pengantar 10gen
• Perbandingan antara Mumps & MongoDB
• MongoDB dibangun untuk Catatan Elektronik
• Pengantar MongoDB
• Keamanan MongoDB
• Upaya Kolaborasi OSEHRA / 10gen
10gen adalah perusahaan di balik MongoDB.

Founded in 2007
• Dwight Merriman, Eliot Horowitz Set the direction &
• Doubleclick, Oracle, Marklogic, HP contribute code to
MongoDB
$73M+ in Funding
Foster community &
• Flybridge, Sequoia, NEA, Union Square ecosystem

Worldwide Expanding Team Provide commercial


services
• 140+ employees
• NY, Palo Alto, London, Dublin, Sydney
Provide MongoDB
management services
Komunitas MongoDB dan ekosistem sedang berkembang.
Community
• 9.000 orang berpartisipasi dalam 23 Hari MongoDB pada tahun 2011 Set the direction &
• 42 Kelompok Pengguna MongoDB contribute code to
• Jangkauan global dengan acara di London, Munich, Paris, Tokyo, dan MongoDB
Beijing

Ekosistem Foster community


• Mitra IaaS dan PaaS menawarkan solusi hosting Cloud
& ecosystem
• Tawaran MongoDB Database-as-a-Service tersedia
• Solusi Intelijen Bisnis, Keamanan, dan Hadoop yang ditawarkan oleh
para mitra
• Perangkat keras dan penyimpanan khusus Provide commercial
services

Provide MongoDB
management services
10gen menyediakan layanan komersial untuk MongoDB.

LANGGANAN Set the direction &


dukungan pengembang dan produksi, lisensi contribute code to
MongoDB
komersial dan Edisi Pelanggan MongoDB
Foster community
KONSULTASI Foster community &
& ecosystem
ecosystem
keahlian dalam basis proyek

LATIHAN Provide
untuk pengembang dan administrator commercial
services
“MediaMath is growing fast and our data volume throughput requirements are
going up very quickly. MongoDB and 10gen have been extremely helpful Provide MongoDB
partners for us in scaling our data infrastructure.” management services
Vince Li
MongoDB is the leading NoSQL solution

#2 ON INDEED’S FASTEST GROWING JOBS JASPERSOFT BIGDATA INDEX


Permintaan untuk
MongoDB, database
NoSQL yang
berorientasi pada
dokumen, melihat
lonjakan terbesar
dengan pertumbuhan
lebih dari 200% pada
tahun 2011.

451 GROUP
GOOGLE SEARCHES “MONGODB INCREASING ITS DOMINANCE”
Perbandingan antara Mumps & MongoDB
• MUMPS • MongoDB
• Dibuat tahun 1960 • Dibuat 2009
• Basis Data Berorientasi Dokumen
• Basis data berorientasi dokumen /
• Didesain dengan teori NoSQL terbaru
objek
• Teknologi Open Source
• Memprediksi C dan memiliki sintaks • Komunitas besar-besaran
dan terminologi yang sangat berbeda • Mendorong inovasi
• Sulit mempekerjakan orang yang tahu • Hemat biaya
teknologi ini • Teknologi panas, banyak buzz, menarik
• Mahal untuk dipelihara pikiran yang paling tajam dan cerdas, basis
pengguna yang besar
• Butuh waktu untuk mengubah /
menyesuaikan dengan persyaratan baru • Mudah untuk menemukan sumber daya
dengan set keterampilan MongoDB
• Sulit diintegrasikan dengan solusi /
teknologi baru • Membangun dari bawah ke atas untuk
Cloud Computing Architecture
Mengapa MongoDB untuk Catatan Elektronik
• Contoh: HL7, EDI, MARC, MODS, DDMS
• Catatan elektronik biasanya dokumen berorientasi
alam: XML, JSON, teks Gratis, atau bahkan biner
• Variasi besar-besaran di bidang yang digunakan
• Masalah data jarang dalam RBMS
• Terus berkembang untuk mendukung semua kasus
bisnis
• Volume dan kecepatan sering dalam skala Big Data
Example HL7 in JSON
{"ClinicalDocument": {
"recordTarget": {
"patientRole": {
"patient": {
"name": {
"given": "Henry",
"family": "Levin",
"suffix": "the 7th” },
"birthTime": {"value": 19320924} },
"providerOrganization": {"name": "Good Health Clinic"} }
},
"author": {
"time": 20000407130000+0500,
"assignedAuthor": {
"assignedPerson": {"name": {
"given": "Robert",
"family": "Dolin",
"prefix": "Dr.” } },
"representedOrganization": { "name": "Good Health Clinic” } }
}
}
MongoDB dibuat
untuk
memudahkan
kode, skala, dan Agile and Scalable
mengelola basis
data.
Asumsi yang berbeda
• Skala secara horizontal di atas perangkat keras komoditas
• RDBMS sangat bagus jadi simpan yang berhasil
• Kueri ad hoc
• Indeks fitur lengkap
• Indeks sekunder
• Apa yang tidak terdistribusi dengan baik?
• Transaksi multi-baris berjalan panjang
• Bergabung
• Kedua artefak dari model data relasional
• Jangan menghomogenkan antarmuka pemrograman
• Penyimpanan lokal warga kelas satu untuk penyimpanan
DB
MongoDB is :

General Full featured Sophisticated


Rich data model
Purpose indexes query language

Easy to Easy mapping to Native language


Simple to setup
object oriented drivers in all
Use code popular languages and manage

Fast & Operates at in-


Auto-sharding Dynamically add /
memory speed remove capacity
Scalable wherever possible built in with no downtime
MongoDB Mudah Digunakan
{
title: ‘MongoDB’,
contributors: [
{ name: ‘Eliot Horowitz’,
email: ‘eliot@10gen.com’ },
{ name: ‘Dwight Merriman’,
email: ‘dwight@10gen.com’ }
],
model: {
relational: false,
awesome: true
}
}
MongoDB Mudah Digunakan

MySQL MongoDB
START TRANSACTION; db.contacts.save( {

INSERT INTO contacts VALUES userName: “joeblow”,


(NULL, ‘joeblow’); emailAddresses: [
INSERT INTO contact_emails VALUES “joe@blow.com”,
( NULL, ”joe@blow.com”, “joseph@blow.com” ] } );
LAST_INSERT_ID() ),
( NULL, “joseph@blow.com”,
LAST_INSERT_ID() );
COMMIT;
MongoDB meningkatkan produktivitas pengembang
Schema Free
• MongoDB tidak membutuhkan skema data yang ditentukan
sebelumnya
• Setiap dokumen bisa memiliki data berbeda!

{name: “will”, name: “jeff”, {name: “brendan”,


eyes: “blue”, eyes: “blue”, aliases: [“el diablo”]}
birthplace: “NY”, loc: [40.7, 73.4],
aliases: [“bill”, “la boss: “ben”}
ciacco”], {name: “matt”,
loc: [32.7, 63.4], pizza: “DiGiorno”,
boss: ”ben”} name: “ben”, height: 72,
hat: ”yes”} loc: [44.6, 71.3]}
MongoDB is fast and scalable
Better data locality In-Memory
Distributed Architecture
Caching

Replication /HA
Relational MongoDB Horizontal Scaling

We just can't get any faster than the way MongoDB handles our data.
Tony Tam
CTO, Wordnik
Keamanan MongoDB
• SSL
• antara klien dan server
• Komunikasi intra-kelompok
• Otorisasi pada tingkat basis data
• Baca Saja / Baca + Tulis / Administrator
• Peta Keamanan (tentatif)
• Otentikasi yang dapat dimasukkan (PAM) 2.4
• Auditing 2.4
• Keamanan tingkat sel 2.6
• Sertifikasi Kriteria Umum
NoSQL populer
untuk MongoDB
10gen adalah
pengembangan membuatnya
perusahaan di
& penyebaran mudah untuk
balik MongoDB
aplikasi data- kode, skala, dan
sentris. mengoperasikan
NoSQL.
Langkah berikutnya
• MongoDB adalah open source dan tidak ada biaya
untuk mengunduh dan menggunakannya
• 10gen adalah pakar dalam teknologi basis data
• OSEHRA adalah pakar dalam solusi Layanan
Kesehatan
Tugas
1. Jelaskan Ilustrasi dari teknologi oracle berikut ini
2. Bandingkan Arsitektur berikut ini
3. Bagaimana cara kerja indeks dan searching pada teknologi database
yang dipakai.
4. Apa manfaat implementasi pada teknologi berikut ini
Thank you for your
attention!

40

Potrebbero piacerti anche