簡體   English   中英

無法創建Firebase數據結構

[英]Trouble creating firebase data structure

對於我的Firebase數據結構,我希望它處理如下內容:

用戶可以創建記錄想法的方式。 他們可以隨便叫它。 Mary Chen通過參數journalMr Owner想要命名它(通過參數) log Firebase將這些文件保存為自己的樹,並為其命名,無論用戶要求為其命名什么參數。

然后出現另一棵樹: whenLoggedIn + \\(parameter) 該樹將yyyy-mm-dd日期保存到相應的帖子中。

例:

{
    "uids": {
        "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": {
            "friends": {
                "IbTuUfmIeO0KOBr5Q4gAqD": true
            },
            "name": "Mary Chen",
            "journal": {
                "entry 1- trader joes": "went to store! :)",
                "entry 2- ate sushi": "took out the garbage today then got free sushi from trader joes!!!"
            },
            "whenLoggedInJournal": {
                "1": "1997-12-25",
                "2": "2016-2-23"
            }
        },
        "L8kBHaGBr5Q4gAqDOhFY29Okepm1": {
            "friends": {
                "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": true
            },
            "name": "Mr Owner",
            "journal": {
                "log 1": "spotted some drunkard in my store",
                "log 2": "drainage pipe clogged with tomatos, I suspect the drunkard",
                "log 3": "did inventory check, 1 less sushi box, suspect the drunkard"
            },
            "whenLoggedInLog": {
                "1": "1997-12-25",
                "2": "2016-2-27",
                "3": "2016-4-2"
            }
        }
    }
}

我通讀了Firebase指南中的“構建數據”,但我不了解如何一次添加樹。 我也想實現扁平化的數據集; 這對我的工作有必要嗎?

推薦的Firebase數據結構是將每個實體拉到其自己的頂級節點。 因此,在您的情況下,這將導致:

{
    "userNames": {
        "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": "Mary Chen",
        "L8kBHaGBr5Q4gAqDOhFY29Okepm1": "Mr Owner"
    },
    "userFriends": {
        "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": {
            "IbTuUfmIeO0KOBr5Q4gAqD": true
        },
        "L8kBHaGBr5Q4gAqDOhFY29Okepm1": {
            "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": true
        }
    },
    "userJournals": {
        "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": {
            "entry 1- trader joes": "went to store! :)",
            "entry 2- ate sushi": "took out the garbage today then got free sushi from trader joes!!!"
        },
        "L8kBHaGBr5Q4gAqDOhFY29Okepm1": {
            "log 1": "spotted some drunkard in my store",
            "log 2": "drainage pipe clogged with tomatos, I suspect the drunkard",
            "log 3": "did inventory check, 1 less sushi box, suspect the drunkard"
        }
    },
    "whenLoggedInJournals": {
        "D0Ez8edYhIbTuUfmIeO0KOq5xVB3": {
            "1": "1997-12-25",
            "2": "2016-2-23"
        },
        "L8kBHaGBr5Q4gAqDOhFY29Okepm1": {
            "1": "1997-12-25",
            "2": "2016-2-27",
            "3": "2016-4-2"
        }
    }
}

這個結構:

  • 使加載部分用戶數據更加容易,例如僅加載名稱
  • 可以更輕松地保護數據,例如,公開用戶名,自己查看好友列表以及自己的好友以及日記和登錄數據只能自己查看

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM