首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分层(Firebase)数据库结构、“Posts/User”或“User/Posts”?

分层(Firebase)数据库结构、“Posts/User”或“User/Posts”?
EN

Stack Overflow用户
提问于 2017-05-28 19:59:27
回答 1查看 307关注 0票数 0

我正在努力构建一个结构,允许用户只访问他们自己的帖子。

我想到了两种可能的方法,但我不确定这两种方法都是最佳实践。我的最终目标是允许用户只对自己的帖子进行读写。

方法A-Posts/User(从安全角度不确定这是否可行)

代码语言:javascript
复制
{
  "posts" : {
    "001" : {
      "text" : "note 1",
      "userID" : "user1"
    },
    "002" : {
      "text" : "note 2",
      "userID" : "user1"
    },
    "003" : {
      "text" : "note 3",
      "userID" : "user2"
    }
  }
}

方法B-用户/发布(不像方法A那样扁平)

代码语言:javascript
复制
{
  "users" : {
    "user1" : {
      "posts" : {
        "001" : {
        "text" : "note 1",
        },
        "002" : {
          "text" : "note 2",
        },
      }
    },
    "user2" : {
      "posts" : {
        "003" : {
        "text" : "note 3",
        },
    },
  }
}

我正在努力遵循准则来保持数据的平顺性。在现实中,帖子项目将不仅仅是文本,但不会延伸到超过两个层次的深度。谢谢你能给我的建议!

EN

回答 1

Stack Overflow用户

发布于 2018-03-26 14:05:17

我会

代码语言:javascript
复制
{
"Users": {
    "user1uniqueRef": {
        "postIDUniqueRef1": {
            "text" : "Here is someText"
            "imageURL" : "https:// etc etc etc"
        "postIDUniqueRef2": {
            "text" : "Here is someText"
            "imageURL" : "https:// etc etc etc"
    "user2uniqueRef": {
       "postIDUniqueRef1": {
           "text" : "Here is someText"
           "imageURL" : "https:// etc etc etc"
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44231473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档