关于更新用户个人资料的颤抖Firestore结构

时间:2020-02-04 15:49:43

标签: google-cloud-firestore

我知道最好通过分隔来标准化Firestore的数据结构。 我最想知道的是是否要更新用户数据。 如果更改了user_id_2的用户名或profile_pic,则无法显示该用户的最新(更新)数据,这意味着无法显示该用户的过去数据。 如何显示当前用户数据并保持推荐的结构?

我从堆栈溢出中引用了this link

{
  "users": {
    "user_id_1": {
      "username": "user one",
      "profile_pic": "some_url",
      "article_counter" : 2,
      "author_of_articules": [
        "article_id_1",
        "article_id_2"
      ],
      "author_of_comments": [
        "comment_id_1"
      ]
    },
    "user_id_2": {
      "username": "user two",
      "profile_pic": "some_url_2",
      "author_of_comments": [
        "comment_id_2"
      ]
    }
  },
  "articles": {
    "article_id_1": {
      "author": {
        "id": "user_id_1",
        "username": "user one",
        "profile_pic": "some_url"
      },
      "title": "Firebase is so cool",
      "comments": {
        "comment_id_1": {
          "comment": "First comment",
          "author": {
            "id": "user_id_1",
            "username": "user one",
            "profile_pic": "some_url"
          }
        },
        "comment_id_2": "I like trains",
        "author": {
          "id": "user_id_2",
          "username": "two",
          "profile_pic": "some_url_2"
        }
      }
    }
  }
}
view rawMultiPath.jso

0 个答案:

没有答案