2016-09-12 17 views
0

我有這樣的數據結構火力地堡數據結構的建議

{ 
"post": { 
    "<postID>": { 
     "postUserID": "<--uid-->", 
     "postUserName": "Nicholas", 
     "postUserIMG": "http://firebase.....", 
     "postImage": "http://firebase.....", 
     "Topic": "It is a nice day", 
     "like": "0" 
    } 
}, 
"user": { 
    "<--uid-->": { 
     "username": "Nicholas", 
     "profilePic": "http://firebase.....", 
     "post": "<postID>" 
    } 
} 
} 

它工作得很好,但是我得到的數據後的一些問題。如果我更改了用戶數據(例如:用戶名),我需要更改用戶的所有發佈數據。我認爲這種結構根本沒有效率。如何重構數據結構以便它可以僅更改一次用戶數據。

回答

0

您應該只存儲用戶標識,然後通過第二個查詢以及來自帖子中的用戶標識來獲取用戶的詳細信息。我會推薦這個數據結構:

{ 
    "post" : { 
     "<postID>" : { 
      "postUserID" : "<--uid-->", 
      "postImage" : "http://firebase.....", 
      "Topic" : "It is a nice day", 
      "like" : "0" 
     } 
    }, 
    "user" : { 
     "<--uid-->" : { 
      "username" : "Nicholas", 
      "profilePic" : "http://firebase.....", 
      "post" : "<postID>" 
     } 
    } 
} 
+0

我試過了,但它不工作,因爲我在表視圖中顯示結構'Post'的帖子。我怎麼能這樣做? –

+1

您必須查詢每個用戶並將其存儲在另一個變量中。 –