gpt4 book ai didi

swift - Firebase 数据结构建议

转载 作者:行者123 更新时间:2023-11-30 13:05:22 25 4
gpt4 key购买 nike

我有这个数据结构

{
"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>"
}
}
}

它工作正常,但是我在发布数据时遇到了一些问题。如果我更改了用户数据(例如:用户名),我需要更改用户的所有帖子数据。我认为这种结构根本没有效率。如何重构数据结构,使其只能更改一次用户数据。

最佳答案

您应该只存储用户 ID,然后在需要时通过使用帖子中的用户 ID 进行第二次查询来获取用户的详细信息。我推荐这个数据结构:

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

关于swift - Firebase 数据结构建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39450399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com