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 က နောက်လူဖတ်ရတာ ပိုကောင်းပါတယ်။