Thuta Learning
ရှာဖွေရန်
IntermediateDevOps & Toolsintermediate

Data ပုံစံ (Structure)

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

Data ပုံစံ (Structure)

Firestore structure ကိုအစကတည်းက စနစ်ကျကျစဉ်းစားထားရင် နောက်ပိုင်း query, rules, performance တွေ အများကြီးကောင်းလာပါတယ်။

Simple Notes App Structure

javascript
users/{userId}
  name: 'Sai'
  email: 'sai@example.com'

notes/{noteId}
  ownerId: '{userId}'
  title: 'Firebase လေ့လာရန်'
  content: 'Auth, Firestore, Storage စမ်းမယ်'
  createdAt: serverTimestamp()
  isPinned: false

ဘာကြောင့် ownerId ထည့်တာလဲ?

ownerId က note ကိုဘယ် user ပိုင်သလဲဆိုတာသိအောင်လုပ်ပေးပါတယ်။ Query တွင်လည်း where('ownerId', '==', user.uid) နဲ့ ကိုယ့် note တွေကိုပဲဖတ်နိုင်ပြီး Security Rules ထဲမှာလည်း owner ကိုစစ်နိုင်ပါတယ်။

Best practice

Document field name တွေကို short ဖြစ်အောင်လုပ်လို့ရပေမဲ့ အဓိပ္ပါယ်ရှင်းနေဖို့ပိုအရေးကြီးပါတယ်။ ttl ထက် title, ct ထက် createdAt က နောက်လူဖတ်ရတာ ပိုကောင်းပါတယ်။

Data ပုံစံ (Structure) | Thuta Learning