কম্পিউটার টিউটোরিয়াল

MongoDB-এ সংখ্যা কি (key) সাব-ডকুমেন্টের মান অ্যাক্সেস করা

MongoDB-এ সাব-ডকুমেন্টের কি (key) যদি সংখ্যা (string সংখ্যা) হয়, তবে ব্র্যাকেট নোটেশন ["key"] ব্যবহার করে অ্যাক্সেস করতে হয়। ডট নোটেশন সংখ্যা কির সাথে কাজ করে না।

নমুনা ডেটা তৈরি (সাব-ডকুমেন্টের কি: "1", "2", "3", "4")

> db.accessSubDocumentDemo.insertOne({
  "Details": {
    "1": {"StudentLowerScore": "33", "StudentHoghScore": "55"},
    "2": {"StudentLowerScore": "45", "StudentHoghScore": "65"},
    "3": {"StudentLowerScore": "39", "StudentHoghScore": "91"},
    "4": {"StudentLowerScore": "41", "StudentHoghScore": "85"}
  }
});
{ "acknowledged": true, "insertedId": ObjectId("5cd3baf0edc6604c74817cd6") }

ডকুমেন্ট দেখুন

> db.accessSubDocumentDemo.find().pretty();
আউটপুট:
{
  "_id": ObjectId("5cd3baf0edc6604c74817cd6"),
  "Details": {
    "1": {"StudentLowerScore": "33", "StudentHoghScore": "55"},
    "2": {"StudentLowerScore": "45", "StudentHoghScore": "65"},
    "3": {"StudentLowerScore": "39", "StudentHoghScore": "91"},
    "4": {"StudentLowerScore": "41", "StudentHoghScore": "85"}
  }
}

কি "1" এর সাব-ডকুমেন্ট অ্যাক্সেস করা (ব্র্যাকেট নোটেশন)

> db.accessSubDocumentDemo.findOne().Details["1"];
আউটপুট:
{ "StudentLowerScore": "33", "StudentHoghScore": "55" }

গুরুত্বপূর্ণ: Details.1 লিখলে এরর হবে বা অन्डিফাইনড রিটার্ন করবে। কি সংখ্যা (string) হলে সবসময় Details["1"] বা Details['1'] ব্যবহার করুন। এটি JavaScript অবজেক্ট প্রোপার্টি অ্যাক্সেসের নিয়ম।

  1. C#-এ Dictionary-এ কী/ভ্যালু জোড়ার সংখ্যা জানা

  2. C#-তে HybridDictionary-এ কী/মান জোড়ার সংখ্যা গণনা করা

  3. C#-এ StringDictionary-র কী-মান জোড়ার সংখ্যা পাওয়া

  4. রেডিস HLEN কমান্ড: হ্যাশ ফিল্ড দ্রুত গণনা করুন