1. correlation with other post
http://teguhth.blogspot.com/2020/12/study-kasus-praktis-belajar-query.html
2. create collection with primarykey
use teguhth
show dbs
show collections
db.createCollection("barang")
db.createCollection("suplier")
db.createCollection("customer")
db.createCollection("pasok")
db.createCollection("pembelian")
show collections
db.barang.find();
db.barang.insert({"_id": "ELK-01","KODE_BARANG":"ELK-01", "NAMA_BARANG":"RICE COOKER", "SATUAN_BARANG":"BUAH", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-02","KODE_BARANG":"ELK-02", "NAMA_BARANG":"LEMARI ES", "SATUAN_BARANG":"UNIT", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-03","KODE_BARANG":"ELK-03", "NAMA_BARANG":"TELEVISI", "SATUAN_BARANG":"UNIT", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-04","KODE_BARANG":"ELK-04", "NAMA_BARANG":"RADIO/TAPE", "SATUAN_BARANG":"BUAH", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-05","KODE_BARANG":"ELK-05", "NAMA_BARANG":"KOMPUTER", "SATUAN_BARANG":"UNIT", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-06","KODE_BARANG":"ELK-06", "NAMA_BARANG":"KIPAS ANGIN", "SATUAN_BARANG":"BUAH", "STOK_BARANG":"20"});
db.barang.find();
db.barang.find().pretty();
db.suplier.find();
db.suplier.insert({"_id": "EJ-01","KODE_SUPLIER":"EJ-01", "NAMA_SUPLIER":"PT ACTRON", "ALAMAT_SUPLIER":"JL THAMRIN 12", "KOTA_SUPLIER":"JAKARTA", "TELEPON_SUPLIER":"(021) 850-2301"});
db.suplier.insert({"_id": "EJ-02","KODE_SUPLIER":"EJ-02", "NAMA_SUPLIER":"PT MULYA ELEKTRONIK", "ALAMAT_SUPLIER":"JL SUDIRMAN 45", "KOTA_SUPLIER":"JAKARTA", "TELEPON_SUPLIER":"(021) 855-4262"});
db.suplier.insert({"_id": "EB-01","KODE_SUPLIER":"EB-01", "NAMA_SUPLIER":"PT ULTRASOUND", "ALAMAT_SUPLIER":"JL SUKARNO HATTA 103", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(021) 522-3305"});
db.suplier.insert({"_id": "EB-02","KODE_SUPLIER":"EB-02", "NAMA_SUPLIER":"PT SUPERTRON", "ALAMAT_SUPLIER":"JL INDUSTRI 37", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(021) 660-4091"});
db.suplier.insert({"_id": "EB-03","KODE_SUPLIER":"EB-03", "NAMA_SUPLIER":"PT OCHANG", "ALAMAT_SUPLIER":"JL KOSAMBI 44", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(022) 850-4444"});
db.suplier.insert({"_id": "EB-04","KODE_SUPLIER":"EB-04", "NAMA_SUPLIER":"PT TUNGGAL JAYA", "ALAMAT_SUPLIER":"JL KIARA CONDONG 77", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(022)740-7777"});
db.suplier.find();
db.suplier.find().pretty();
db.customer.find();
db.customer.insert({"_id": "J-0001","KODE_CUSTOMER":"J-0001", "NAMA_CUSTOMER":"TOKO KARISMA", "ALAMAT_CUSTOMER":"JL CIMANGGIS 34", "KOTA_CUSTOMER":"JAKARTA", "TELEPON_CUSTOMER":"(021) 856-4209"});
db.customer.insert({"_id": "J-0002","KODE_CUSTOMER":"J-0002", "NAMA_CUSTOMER":"TOKO AYU", "ALAMAT_CUSTOMER":"JL CIMANGGIS 12", "KOTA_CUSTOMER":"JAKARTA", "TELEPON_CUSTOMER":"(021) 856-1321"});
db.customer.insert({"_id": "B-0001","KODE_CUSTOMER":"B-0001", "NAMA_CUSTOMER":"TOKO WARNA", "ALAMAT_CUSTOMER":"JL ABC 234", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 432-6635"});
db.customer.insert({"_id": "B-0002","KODE_CUSTOMER":"B-0002", "NAMA_CUSTOMER":"TOKO SURYA", "ALAMAT_CUSTOMER":"JL ABC 309", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 432-6024"});
db.customer.insert({"_id": "B-0003","KODE_CUSTOMER":"B-0003", "NAMA_CUSTOMER":"TOKO MAHARANI", "ALAMAT_CUSTOMER":"JL KOPO 333", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 856-3333"});
db.customer.insert({"_id": "B-0004","KODE_CUSTOMER":"B-0004", "NAMA_CUSTOMER":"TOKO MULYA", "ALAMAT_CUSTOMER":"JL OTISTA 555", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 422-5555"});
db.customer.find();
db.customer.find().pretty();
db.pasok.find();
db.pasok.insert({"_id": "PAS-E001","KODE_PASOK":"PAS-E001", "KODE_BARANG":"ELK-01", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"1-Jan-02", "JUMLAH_PASOK":"8"});
db.pasok.insert({"_id": "PAS-E002","KODE_PASOK":"PAS-E002", "KODE_BARANG":"ELK-01", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"1-Jan-02", "JUMLAH_PASOK":"5"});
db.pasok.insert({"_id": "PAS-E003","KODE_PASOK":"PAS-E003", "KODE_BARANG":"ELK-02", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"1-Feb-02", "JUMLAH_PASOK":"2"});
db.pasok.insert({"_id": "PAS-E004","KODE_PASOK":"PAS-E004", "KODE_BARANG":"ELK-02", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"2-Feb-02", "JUMLAH_PASOK":"3"});
db.pasok.insert({"_id": "PAS-E005","KODE_PASOK":"PAS-E005", "KODE_BARANG":"ELK-02", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"1-Jan-02", "JUMLAH_PASOK":"2"});
db.pasok.insert({"_id": "PAS-E006","KODE_PASOK":"PAS-E006", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"3-Mar-02", "JUMLAH_PASOK":"5"});
db.pasok.insert({"_id": "PAS-E007","KODE_PASOK":"PAS-E007", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"4-Mar-02", "JUMLAH_PASOK":"2"});
db.pasok.insert({"_id": "PAS-E008","KODE_PASOK":"PAS-E008", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"3-Mar-02", "JUMLAH_PASOK":"3"});
db.pasok.insert({"_id": "PAS-E009","KODE_PASOK":"PAS-E009", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"13-Mar-02", "JUMLAH_PASOK":"4"});
db.pasok.insert({"_id": "PAS-E010","KODE_PASOK":"PAS-E010", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"13-Mar-02", "JUMLAH_PASOK":"3"});
db.pasok.insert({"_id": "PAS-E011","KODE_PASOK":"PAS-E011", "KODE_BARANG":"ELK-04", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"22-Apr-02", "JUMLAH_PASOK":"12"});
db.pasok.insert({"_id": "PAS-E012","KODE_PASOK":"PAS-E012", "KODE_BARANG":"ELK-04", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"30-Apr-02", "JUMLAH_PASOK":"9"});
db.pasok.find();
db.pasok.find().pretty();
db.pembelian.find();
db.pembelian.insert({"_id": "BEL-E001","KODE_PEMBELIAN":"BEL-E001", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"20-May-02", "JUMLAH_PEMBELIAN":"3"});
db.pembelian.insert({"_id": "BEL-E002","KODE_PEMBELIAN":"BEL-E002", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"21-May-02", "JUMLAH_PEMBELIAN":"4"});
db.pembelian.insert({"_id": "BEL-E003","KODE_PEMBELIAN":"BEL-E003", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"20-May-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E004","KODE_PEMBELIAN":"BEL-E004", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"B-0001", "TANGGAL_PEMBELIAN":"20-May-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E005","KODE_PEMBELIAN":"BEL-E005", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"B-0002", "TANGGAL_PEMBELIAN":"22-May-02", "JUMLAH_PEMBELIAN":"3"});
db.pembelian.insert({"_id": "BEL-E006","KODE_PEMBELIAN":"BEL-E006", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"24-Jun-02", "JUMLAH_PEMBELIAN":"1"});
db.pembelian.insert({"_id": "BEL-E007","KODE_PEMBELIAN":"BEL-E007", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"24-Jun-02", "JUMLAH_PEMBELIAN":"1"});
db.pembelian.insert({"_id": "BEL-E008","KODE_PEMBELIAN":"BEL-E008", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"B-0001", "TANGGAL_PEMBELIAN":"25-Jun-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E009","KODE_PEMBELIAN":"BEL-E009", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"B-0002", "TANGGAL_PEMBELIAN":"25-Jun-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E010","KODE_PEMBELIAN":"BEL-E010", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"20-Jun-02", "JUMLAH_PEMBELIAN":"5"});
db.pembelian.insert({"_id": "BEL-E011","KODE_PEMBELIAN":"BEL-E011", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"2-Jul-02", "JUMLAH_PEMBELIAN":"4"});
db.pembelian.insert({"_id": "BEL-E012","KODE_PEMBELIAN":"BEL-E012", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"B-0001", "TANGGAL_PEMBELIAN":"4-Jul-02", "JUMLAH_PEMBELIAN":"6"});
db.pembelian.insert({"_id": "BEL-E013","KODE_PEMBELIAN":"BEL-E013", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"10-Jul-02", "JUMLAH_PEMBELIAN":"5"});
db.pembelian.insert({"_id": "BEL-E014","KODE_PEMBELIAN":"BEL-E014", "KODE_BARANG":"ELK-04", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"15-Jul-02", "JUMLAH_PEMBELIAN":"12"});
db.pembelian.insert({"_id": "BEL-E015","KODE_PEMBELIAN":"BEL-E015", "KODE_BARANG":"ELK-04", "KODE_CUSTOMER":"B-0002", "TANGGAL_PEMBELIAN":"17-Jul-02", "JUMLAH_PEMBELIAN":"15"});
db.pembelian.find();
db.pembelian.find().pretty();
3. show sample result query
db.barang.find();
db.suplier.find();
db.customer.find();
db.pasok.find();
db.pembelian.find();
db.pembelian.find().sort({ KODE_PEMBELIAN: 1 });
4. example output using column
var headerPrinted = false;
db.pembelian.find().sort({ KODE_PEMBELIAN: 1 }).forEach(function(doc) {
if (!headerPrinted) {
print("=============================================================================================================================");
print("|\tKODE_PEMBELIAN\t|\tKODE_BARANG\t|\tKODE_CUSTOMER\t|\tTANGGAL_PEMBELIAN\t|\tJUMLAH_PEMBELIAN\t|");
print("=============================================================================================================================");
headerPrinted = true;
}
print("|\t" + doc.KODE_PEMBELIAN + "\t|\t" + doc.KODE_BARANG + "\t|\t" + doc.KODE_CUSTOMER + "\t|\t" + doc.TANGGAL_PEMBELIAN + "\t|\t" + doc.JUMLAH_PEMBELIAN + "\t|");
});
http://teguhth.blogspot.com/2020/12/study-kasus-praktis-belajar-query.html
2. create collection with primarykey
use teguhth
show dbs
show collections
db.createCollection("barang")
db.createCollection("suplier")
db.createCollection("customer")
db.createCollection("pasok")
db.createCollection("pembelian")
show collections
db.barang.find();
db.barang.insert({"_id": "ELK-01","KODE_BARANG":"ELK-01", "NAMA_BARANG":"RICE COOKER", "SATUAN_BARANG":"BUAH", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-02","KODE_BARANG":"ELK-02", "NAMA_BARANG":"LEMARI ES", "SATUAN_BARANG":"UNIT", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-03","KODE_BARANG":"ELK-03", "NAMA_BARANG":"TELEVISI", "SATUAN_BARANG":"UNIT", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-04","KODE_BARANG":"ELK-04", "NAMA_BARANG":"RADIO/TAPE", "SATUAN_BARANG":"BUAH", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-05","KODE_BARANG":"ELK-05", "NAMA_BARANG":"KOMPUTER", "SATUAN_BARANG":"UNIT", "STOK_BARANG":"20"});
db.barang.insert({"_id": "ELK-06","KODE_BARANG":"ELK-06", "NAMA_BARANG":"KIPAS ANGIN", "SATUAN_BARANG":"BUAH", "STOK_BARANG":"20"});
db.barang.find();
db.barang.find().pretty();
db.suplier.find();
db.suplier.insert({"_id": "EJ-01","KODE_SUPLIER":"EJ-01", "NAMA_SUPLIER":"PT ACTRON", "ALAMAT_SUPLIER":"JL THAMRIN 12", "KOTA_SUPLIER":"JAKARTA", "TELEPON_SUPLIER":"(021) 850-2301"});
db.suplier.insert({"_id": "EJ-02","KODE_SUPLIER":"EJ-02", "NAMA_SUPLIER":"PT MULYA ELEKTRONIK", "ALAMAT_SUPLIER":"JL SUDIRMAN 45", "KOTA_SUPLIER":"JAKARTA", "TELEPON_SUPLIER":"(021) 855-4262"});
db.suplier.insert({"_id": "EB-01","KODE_SUPLIER":"EB-01", "NAMA_SUPLIER":"PT ULTRASOUND", "ALAMAT_SUPLIER":"JL SUKARNO HATTA 103", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(021) 522-3305"});
db.suplier.insert({"_id": "EB-02","KODE_SUPLIER":"EB-02", "NAMA_SUPLIER":"PT SUPERTRON", "ALAMAT_SUPLIER":"JL INDUSTRI 37", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(021) 660-4091"});
db.suplier.insert({"_id": "EB-03","KODE_SUPLIER":"EB-03", "NAMA_SUPLIER":"PT OCHANG", "ALAMAT_SUPLIER":"JL KOSAMBI 44", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(022) 850-4444"});
db.suplier.insert({"_id": "EB-04","KODE_SUPLIER":"EB-04", "NAMA_SUPLIER":"PT TUNGGAL JAYA", "ALAMAT_SUPLIER":"JL KIARA CONDONG 77", "KOTA_SUPLIER":"BANDUNG", "TELEPON_SUPLIER":"(022)740-7777"});
db.suplier.find();
db.suplier.find().pretty();
db.customer.find();
db.customer.insert({"_id": "J-0001","KODE_CUSTOMER":"J-0001", "NAMA_CUSTOMER":"TOKO KARISMA", "ALAMAT_CUSTOMER":"JL CIMANGGIS 34", "KOTA_CUSTOMER":"JAKARTA", "TELEPON_CUSTOMER":"(021) 856-4209"});
db.customer.insert({"_id": "J-0002","KODE_CUSTOMER":"J-0002", "NAMA_CUSTOMER":"TOKO AYU", "ALAMAT_CUSTOMER":"JL CIMANGGIS 12", "KOTA_CUSTOMER":"JAKARTA", "TELEPON_CUSTOMER":"(021) 856-1321"});
db.customer.insert({"_id": "B-0001","KODE_CUSTOMER":"B-0001", "NAMA_CUSTOMER":"TOKO WARNA", "ALAMAT_CUSTOMER":"JL ABC 234", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 432-6635"});
db.customer.insert({"_id": "B-0002","KODE_CUSTOMER":"B-0002", "NAMA_CUSTOMER":"TOKO SURYA", "ALAMAT_CUSTOMER":"JL ABC 309", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 432-6024"});
db.customer.insert({"_id": "B-0003","KODE_CUSTOMER":"B-0003", "NAMA_CUSTOMER":"TOKO MAHARANI", "ALAMAT_CUSTOMER":"JL KOPO 333", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 856-3333"});
db.customer.insert({"_id": "B-0004","KODE_CUSTOMER":"B-0004", "NAMA_CUSTOMER":"TOKO MULYA", "ALAMAT_CUSTOMER":"JL OTISTA 555", "KOTA_CUSTOMER":"BANDUNG", "TELEPON_CUSTOMER":"(022) 422-5555"});
db.customer.find();
db.customer.find().pretty();
db.pasok.find();
db.pasok.insert({"_id": "PAS-E001","KODE_PASOK":"PAS-E001", "KODE_BARANG":"ELK-01", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"1-Jan-02", "JUMLAH_PASOK":"8"});
db.pasok.insert({"_id": "PAS-E002","KODE_PASOK":"PAS-E002", "KODE_BARANG":"ELK-01", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"1-Jan-02", "JUMLAH_PASOK":"5"});
db.pasok.insert({"_id": "PAS-E003","KODE_PASOK":"PAS-E003", "KODE_BARANG":"ELK-02", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"1-Feb-02", "JUMLAH_PASOK":"2"});
db.pasok.insert({"_id": "PAS-E004","KODE_PASOK":"PAS-E004", "KODE_BARANG":"ELK-02", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"2-Feb-02", "JUMLAH_PASOK":"3"});
db.pasok.insert({"_id": "PAS-E005","KODE_PASOK":"PAS-E005", "KODE_BARANG":"ELK-02", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"1-Jan-02", "JUMLAH_PASOK":"2"});
db.pasok.insert({"_id": "PAS-E006","KODE_PASOK":"PAS-E006", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"3-Mar-02", "JUMLAH_PASOK":"5"});
db.pasok.insert({"_id": "PAS-E007","KODE_PASOK":"PAS-E007", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"4-Mar-02", "JUMLAH_PASOK":"2"});
db.pasok.insert({"_id": "PAS-E008","KODE_PASOK":"PAS-E008", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"3-Mar-02", "JUMLAH_PASOK":"3"});
db.pasok.insert({"_id": "PAS-E009","KODE_PASOK":"PAS-E009", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"13-Mar-02", "JUMLAH_PASOK":"4"});
db.pasok.insert({"_id": "PAS-E010","KODE_PASOK":"PAS-E010", "KODE_BARANG":"ELK-03", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"13-Mar-02", "JUMLAH_PASOK":"3"});
db.pasok.insert({"_id": "PAS-E011","KODE_PASOK":"PAS-E011", "KODE_BARANG":"ELK-04", "KODE_SUPLIER":"EJ-01", "TANGGAL_PASOK":"22-Apr-02", "JUMLAH_PASOK":"12"});
db.pasok.insert({"_id": "PAS-E012","KODE_PASOK":"PAS-E012", "KODE_BARANG":"ELK-04", "KODE_SUPLIER":"EJ-02", "TANGGAL_PASOK":"30-Apr-02", "JUMLAH_PASOK":"9"});
db.pasok.find();
db.pasok.find().pretty();
db.pembelian.find();
db.pembelian.insert({"_id": "BEL-E001","KODE_PEMBELIAN":"BEL-E001", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"20-May-02", "JUMLAH_PEMBELIAN":"3"});
db.pembelian.insert({"_id": "BEL-E002","KODE_PEMBELIAN":"BEL-E002", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"21-May-02", "JUMLAH_PEMBELIAN":"4"});
db.pembelian.insert({"_id": "BEL-E003","KODE_PEMBELIAN":"BEL-E003", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"20-May-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E004","KODE_PEMBELIAN":"BEL-E004", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"B-0001", "TANGGAL_PEMBELIAN":"20-May-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E005","KODE_PEMBELIAN":"BEL-E005", "KODE_BARANG":"ELK-01", "KODE_CUSTOMER":"B-0002", "TANGGAL_PEMBELIAN":"22-May-02", "JUMLAH_PEMBELIAN":"3"});
db.pembelian.insert({"_id": "BEL-E006","KODE_PEMBELIAN":"BEL-E006", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"24-Jun-02", "JUMLAH_PEMBELIAN":"1"});
db.pembelian.insert({"_id": "BEL-E007","KODE_PEMBELIAN":"BEL-E007", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"24-Jun-02", "JUMLAH_PEMBELIAN":"1"});
db.pembelian.insert({"_id": "BEL-E008","KODE_PEMBELIAN":"BEL-E008", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"B-0001", "TANGGAL_PEMBELIAN":"25-Jun-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E009","KODE_PEMBELIAN":"BEL-E009", "KODE_BARANG":"ELK-02", "KODE_CUSTOMER":"B-0002", "TANGGAL_PEMBELIAN":"25-Jun-02", "JUMLAH_PEMBELIAN":"2"});
db.pembelian.insert({"_id": "BEL-E010","KODE_PEMBELIAN":"BEL-E010", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"20-Jun-02", "JUMLAH_PEMBELIAN":"5"});
db.pembelian.insert({"_id": "BEL-E011","KODE_PEMBELIAN":"BEL-E011", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"2-Jul-02", "JUMLAH_PEMBELIAN":"4"});
db.pembelian.insert({"_id": "BEL-E012","KODE_PEMBELIAN":"BEL-E012", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"B-0001", "TANGGAL_PEMBELIAN":"4-Jul-02", "JUMLAH_PEMBELIAN":"6"});
db.pembelian.insert({"_id": "BEL-E013","KODE_PEMBELIAN":"BEL-E013", "KODE_BARANG":"ELK-03", "KODE_CUSTOMER":"J-0001", "TANGGAL_PEMBELIAN":"10-Jul-02", "JUMLAH_PEMBELIAN":"5"});
db.pembelian.insert({"_id": "BEL-E014","KODE_PEMBELIAN":"BEL-E014", "KODE_BARANG":"ELK-04", "KODE_CUSTOMER":"J-0002", "TANGGAL_PEMBELIAN":"15-Jul-02", "JUMLAH_PEMBELIAN":"12"});
db.pembelian.insert({"_id": "BEL-E015","KODE_PEMBELIAN":"BEL-E015", "KODE_BARANG":"ELK-04", "KODE_CUSTOMER":"B-0002", "TANGGAL_PEMBELIAN":"17-Jul-02", "JUMLAH_PEMBELIAN":"15"});
db.pembelian.find();
db.pembelian.find().pretty();
3. show sample result query
db.barang.find();
db.suplier.find();
db.customer.find();
db.pasok.find();
db.pembelian.find();
db.pembelian.find().sort({ KODE_PEMBELIAN: 1 });
4. example output using column
var headerPrinted = false;
db.pembelian.find().sort({ KODE_PEMBELIAN: 1 }).forEach(function(doc) {
if (!headerPrinted) {
print("=============================================================================================================================");
print("|\tKODE_PEMBELIAN\t|\tKODE_BARANG\t|\tKODE_CUSTOMER\t|\tTANGGAL_PEMBELIAN\t|\tJUMLAH_PEMBELIAN\t|");
print("=============================================================================================================================");
headerPrinted = true;
}
print("|\t" + doc.KODE_PEMBELIAN + "\t|\t" + doc.KODE_BARANG + "\t|\t" + doc.KODE_CUSTOMER + "\t|\t" + doc.TANGGAL_PEMBELIAN + "\t|\t" + doc.JUMLAH_PEMBELIAN + "\t|");
});
No comments:
Post a Comment