Node.js ကျူတိုရီရယ်

Node.js ပင်မစာမျက်နှာ Node.js နိဒါန်း Node.js ကို စတင်လိုက်ပါ။ Node.js မော်ဂျူးများ Node.js HTTP မော်ဂျူး Node.js ဖိုင်စနစ် Node.js URL မော်ဂျူး Node.js NPM Node.js ပွဲများ Node.js ဖိုင်များ အပ်လုဒ်လုပ်ခြင်း။ Node.js အီးမေးလ်

Node.js MySQL

MySQL စတင်လိုက်ပါ။ MySQL ဒေတာဘေ့စ်ဖန်တီးပါ။ MySQL ဇယားဖန်တီးပါ။ MySQL ထဲသို့ ထည့်သွင်းပါ။ MySQL မှ ရွေးချယ်ပါ။ MySQL ဘယ်မှာလဲ။ MySQL Order By MySQL ကိုဖျက်ပါ။ MySQL Drop Table MySQL အပ်ဒိတ် MySQL ကန့်သတ်ချက် MySQL Join

Node.js MongoDB

MongoDB စတင်လိုက်ပါ။ MongoDB ဒေတာဘေ့စ်ဖန်တီးပါ။ MongoDB သည် Collection ကိုဖန်တီးပါ။ MongoDB ထည့်သွင်းပါ။ MongoDB ကိုရှာပါ။ MongoDB မေးခွန်း MongoDB အမျိုးအစား MongoDB ကိုဖျက်ပါ။ MongoDB Drop Collection MongoDB အပ်ဒိတ် MongoDB ကန့်သတ်ချက် MongoDB Join

Raspberry Pi

RasPi စတင်လိုက်ပါ။ RasPi GPIO နိဒါန်း RasPi မှိတ်တုတ်မှိတ်တုတ် LED RasPi LED နှင့် ခလုတ်နှိပ်ပါ။ RasPi စီးဆင်းနေသော LED များ RasPi WebSocket RasPi RGB LED WebSocket RasPi အစိတ်အပိုင်းများ

Node.js အ ကိုး အကား

Built-in Modules များ

Node.js MongoDB Join


စုစည်းမှုများကို ချိတ်ဆက်ပါ။

MongoDB သည် ဆက်စပ်ဒေတာဘေ့စ်တစ်ခုမဟုတ်သော်လည်း စတိတ်ကိုအသုံးပြု၍ ဘယ်ဘက်အပြင်ဘက်တွင်ပါဝင်မှုကို လုပ်ဆောင်နိုင်သည် $lookup

အဆင့်သည် လက်ရှိ $lookupစုစည်းမှုနှင့်အတူ သင်ပါဝင်လိုသည့် စုစည်းမှုနှင့် မည်သည့်အကွက်များနှင့် ကိုက်ညီသင့်သည်ကို သတ်မှတ်ပေးပါသည်။

သင့်တွင် "အမှာစာများ" စုဆောင်းမှုနှင့် "ထုတ်ကုန်များ" စုဆောင်းမှုတစ်ခုရှိနေသည်ဟု သုံးသပ်ကြည့်ပါ-

အမိန့်

[
  { _id: 1, product_id: 154, status: 1 }
]

ထုတ်ကုန်များ

[
  { _id: 154, name: 'Chocolate Heaven' },
  { _id: 155, name: 'Tasty Lemons' },
  { _id: 156, name: 'Vanilla Dreams' }
]

ဥပမာ

ကိုက်ညီသော "ထုတ်ကုန်များ" စာရွက်စာတမ်း(များ) "အော်ဒါများ" စုစည်းမှုတွင် ပါဝင်ပါ-

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var dbo = db.db("mydb");
  dbo.collection('orders').aggregate([
    { $lookup:
       {
         from: 'products',
         localField: 'product_id',
         foreignField: '_id',
         as: 'orderdetails'
       }
     }
    ]).toArray(function(err, res) {
    if (err) throw err;
    console.log(JSON.stringify(res));
    db.close();
  });
});

"demo_mongodb_join.js" ဟုခေါ်သော ဖိုင်တစ်ခုတွင် အထက်ကုဒ်ကို သိမ်းဆည်းပြီး ဖိုင်ကို ဖွင့်ပါ။

"demo_mongodb_join.js" ကိုဖွင့်ပါ

C:\Users\Your Name>node demo_mongodb_join.js

သင့်အား ဤရလဒ်ကို ပေးလိမ့်မည်-

[
  { "_id": 1, "product_id": 154, "status": 1, "orderdetails": [
    { "_id": 154, "name": "Chocolate Heaven" } ]
  }
]

အထက်ဖော်ပြပါ ရလဒ်များမှ သင်တွေ့မြင်ရသည့်အတိုင်း၊ ထုတ်ကုန်စုဆောင်းမှုမှ ကိုက်ညီသောစာရွက်စာတမ်းကို အမှာစာစုစည်းမှုတွင် ခင်းကျင်းမှုတစ်ခုအဖြစ် ထည့်သွင်းထားသည်။