Untuk menginstal Microsoft DocumentDB menggunakan Docker, Anda perlu menginstal Docker terlebih dahulu.
Kemudian klon repositori DocumentDB dari GitHub serta buat citra Docker dari repositori tersebut dan terakhir jalankan citra tersebut sebagai kontainer untuk memulai server DocumentDB secara lokal.
Instal Docker
Ikuti langkah-langkah berikut untuk menginstal Docker melalui link Docker dan ikuti langkah-lngkh yang ada di dokumentasi docker tersebut.
Klon repositori DocumentDB
git clone https://github.com/microsoft/documentdb.git
Buat image Docker dan navigasikan ke repositori kloning
docker build . -f .devcontainer/Dockerfile -t documentdb
Jalankan Image Docker sebagai kontainer
docker run -v $(pwd):/home/documentdb/code -it documentdb /bin/bash
Build dan deploy binaries
cd code make sudo make install
Inisialisasi server DocumentDB dan kelola dependensi
./scripts/start_oss_server.sh -t documentdb
Hubungkan ke shell pSQL
psql -p 9712 -h localhost -d postgres
After following the steps above, you are now all set to use DocumentDB locally.
Beberapa contoh CRUD sederhana setelah instalasi
Untuk membuat koleksi ‘ patient’ di database ‘documentdb’:
SELECT documentdb_api.create_collection('documentdb','patient');
Untuk memasukkan dokumen ke dalam koleksi patient
select from documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P001", "name": "Alice Smith", "age": 30, "phone_number": "555-0123", "registration_year": "2022","conditions": ["Diabetes", "Hypertension"]}');
Untuk memilih dokumen:
select 1 from documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P002", "name": "Bob Johnson", "age": 45, "phone_number": "555-0456", "registration_year": "2022", "conditions": ["Asthma"]}');
Query selanjutnya
select 1 from documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P003", "name": "Charlie Brown", "age": 29, "phone_number": "555-0789", "registration_year": "2023", "conditions": ["Allergy", "Anemia"]}');
Untuk selanjutnya Kalian dapat melihat Dokumentasi Kami di GitHub, hubungi dapat menghubungi kami di Discord, mulailah bereksperimen dengan DocumentDB sekarang.