2016-09-12 18 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

您必须查询每个用户并将其存储在另一个变量中。 –