文件夹系统的Firebase数据结构/索引

时间:2014-11-17 17:28:29

标签: firebase firebase-realtime-database nosql

我有以下数据结构:

"users": {
    $userid: {
        "forms": {
            "ID_OF_FORM 1": { "name": "Name goes here" },
            "ID_OF_FORM 2": { "name": "Name goes here" }
        }
    }
}

我希望能够把我的"形式"在文件夹系统中,为用户更好地组织所有这些。现在我用/users/auth.id/forms/ID打电话给他们。我计划将对象放在forms对象中,但我不认为如果我这样做,我只能用表单ID 来调用它们。

我无法理解如何存储这些文件夹,以便轻松显示这些文件夹。

  • 我需要显示 root 中的所有文件夹或活动ID 用户当前所在的文件夹。
  • 我还需要能够使用
  • 形式的id来调用表单

你认为这会有用吗?有没有人有更好的建议去做这件事?

"users": {
    $userid: {
        "forms": {
            "ID_OF_FORM 1": { "name": "Name goes here", "folder_id": "ID_OF_FOLDER" },
            "ID_OF_FORM 2": { "name": "Name goes here", "folder_id": "ID_OF_FOLDER" }
        },
        "folders": {
            "ID_OF_FOLDER 1": { "name": "name of folder" },
            "ID_OF_FOLDER 2": { "name": "name of folder" },
            "ID_OF_FOLDER 3": { 
                "name": "name of folder",
                "ID_OF_FOLDER 4": { "name": "would this even work" }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

对我来说很好看,虽然很难确定除非知道所有用例(StackOverflow不是真正的论坛)。

我会将folders改为:

    "folders": {
        "ID_OF_FOLDER 1": { "name": "name of folder" },
        "ID_OF_FOLDER 2": { "name": "name of folder" },
        "ID_OF_FOLDER 3": { "name": "name of folder" },
        "ID_OF_FOLDER 4": { "name": "would this even work", "folder_id": "ID_OF_FOLDER 3" }
    }

否则,您可能会超过Firebase对树的深度施加的32级限制。好消息是你可以通过它的ID直接访问任何文件夹。

可能考虑为所有项目类型使用单个顶级节点,包括表单和文件夹(以及在构建应用程序时可能出现的任何其他内容):

    "items": {
        "ID_OF_FORM 1": { "type": "form", "name": "Name goes here", "folder_id": "ID_OF_FOLDER" },
        "ID_OF_FORM 2": { "type": "form", "name": "Name goes here", "folder_id": "ID_OF_FOLDER" }
        "ID_OF_FOLDER 1": { "type": "folder", "name": "name of folder" },
        "ID_OF_FOLDER 2": { "type": "folder", "name": "name of folder" },
        "ID_OF_FOLDER 3": { "type": "folder", "name": "name of folder" },
        "ID_OF_FOLDER 4": { "type": "folder", "name": "would this even work", "folder_id": "ID_OF_FOLDER 3" }
    }

但我认为这对您的用例目前来说并不太有益。鉴于你所说的,文件夹和表单之间的分离看起来非常好。