Node.js MongoDB စုစည်းမှုကို ဖန်တီး ပါ။
MongoDB တွင် စုစည်းမှု တစ်ခုသည် MySQL ရှိ ဇယား တစ်ခုနှင့်အတူတူဖြစ်သည်။
စုစည်းမှုဖန်တီးခြင်း။
MongoDB တွင် စုစည်းမှုတစ်ခုကို ဖန်တီးရန်၊ createCollection()
နည်းလမ်းကို အသုံးပြုပါ-
ဥပမာ
"ဖောက်သည်များ" ဟုခေါ်သော စုစည်းမှုတစ်ခုကို ဖန်တီးပါ-
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
dbo.createCollection("customers",
function(err, res) {
if (err) throw err;
console.log("Collection created!");
db.close();
});
});
"demo_mongodb_createcollection.js" ဟုခေါ်သော ဖိုင်တစ်ခုတွင် အထက်ကုဒ်ကို သိမ်းဆည်းပြီး ဖိုင်ကို ဖွင့်ပါ။
"demo_mongodb_createcollection.js" ကိုဖွင့်ပါ
C:\Users\Your Name>node demo_mongodb_createcollection.js
သင့်အား ဤရလဒ်ကို ပေးလိမ့်မည်-
Collection created!
အရေးကြီးသည်- MongoDB တွင်၊ အကြောင်းအရာမရရှိမချင်း စုစည်းမှုတစ်ခုကို ဖန်တီးမထားပါ။
MongoDB သည် စုစည်းမှုကို အမှန်တကယ်မဖန်တီးမီ စာရွက်စာတမ်းတစ်ခုကို သင်ထည့်သွင်းပြီးသည်အထိ စောင့်ပါသည်။