Firebase RealTime DataBase 以下簡稱 FRDB
Structure Your Database
這份指南包含了資料架構中的一些重要觀念,以及在FRDB中構建JSON數據的最佳範例。
This guide covers some of the key concepts in data architecture and best practices for structuring the JSON data in your Firebase Realtime Database.
要建立一個架構優良的資料庫,有許多地方需要考量。
其中最重要的是「設計資料如何儲存與讀取」,並盡可能簡化資料檢索的過程。
Building a properly structured database requires quite a bit of forethought. Most importantly, you need to plan for how data is going to be saved and later retrieved to make that process as easy as possible.
How data is structured: it's a JSON tree
在FRDB中,資料都是以JSON物件的形式儲存的(注意:並沒有JSON Array),你可以把FRDB想成放在雲端的一顆JSON Tree,
與傳統的SQL DB不同的是,FRDB中並沒有任何資料表或是資料列。而當你增加資料進JSON Tree之後,資料將成為現有JSON結構中的一個節點,由於以JSON物件的形式儲存,每個物件都會有自己所對應到的key,你可以自己決定key的名稱,像是UserID、語意化的名稱等等,或是也可以由Firebase動態幫妳生成雜湊的key
All Firebase Realtime Database data is stored as JSON objects. You can think of the database as a cloud-hosted JSON tree. Unlike a SQL database, there are no tables or records. When you add data to the JSON tree, it becomes a node in the existing JSON structure with an associated key. You can provide your own keys, such as user IDs or semantic names, or they can be provided for you usingpush()
.
If you create your own keys, they must be UTF-8 encoded, can be a maximum of 768 bytes, and cannot contain
.
,$
,#
,[
,]
,/
, or ASCII control characters 0-31 or 127.