javascript - 正确的扁平化数据模型和 noSQL 数据结构

标签 javascript json data-structures firebase data-modeling

我目前正在使用一项服务构建一个小型应用程序,该服务需要并提倡使用“扁平化”数据模型(该服务是 Firebase)。

由于我之前没有使用数据模型的经验,所以我想知道我是否以正确的方式扁平化了我的数据。

这是我开始使用的数据模型模型(它有很多嵌套节点):

// Core data model
    {
        // All registered users 
        "users": {
            // User assigned ID
            "userid": {
                // User information
                "password": "password",
                "email": "test@gmail.com",
                "name": "test",
                // Saved user entries
                "entries": {
                    // Entry ID
                    "entryid": {
                        // Firt part of entry
                        "first": {
                            "one": "yay",
                            "two": "nice",
                            "three": "man"
                        },
                        "second": {
                            "one": "wow",
                            "two": "hmm",
                            "three": "nope"
                        }
                    },

                    "entryid2": {
                        "first": {
                            "one": "kewl",
                            "two": "look",
                            "three": "this"
                       }
                    }
                }
            },
            "id2": {
                // ... and so on
            }
        }
    }

这是我的“扁平化”版本:

// Flattened model
    {
        // All registered users 
        "users": {
            // User assigned ID
            "userid": {
                // User information
                "password": "password",
                "email": "test@gmail.com",
                "name": "test"
            },
            "userid2": {
                // ... and so on
            }
        },
        // All user entries
        "entries": {
            // User assigned UD (entries for particular user)
            "userid": {
                "first": {
                    "one": "yay",
                    "two": "nice",
                    "three": "man"
                },
                "second": {
                    "one": "kewl",
                    "two": "look",
                    "three": "this"
                }
            },
            "userid2": {
                "one": "wow",
                "two": "hmm",
                "three": "nope"
            }
        }
    }

了解这是否是一种以扁平化方式组织数据的正确(或至少可能)方式将非常有帮助。

最佳答案

确实没有 100% 正确的数据存储方式。它结合了从精神开销 Angular 来看对您有用的方法和您正在使用的任何商店的技术限制。

尽管 Firebase 确实提倡“扁平数据结构”,但您的任何一个代码示例都没有接近他们的技术极限。

来自Understanding Data Docs :

A child node's key cannot be longer than 768 bytes, nor deeper than 32 levels

无论哪种方式,您都只会深入几个节点,我建议您选择您最能理解和沟通的数据模型,因为您不太可能在上面发布的范围内遇到技术限制。

关于javascript - 正确的扁平化数据模型和 noSQL 数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37105413/

相关文章:

javascript - 获取 SharePoint 2007 客户端的当前用户名

javascript - 如何不等待 jQuery $.get 函数完成

python - 在 Python 中序列化用户定义的类

php - getJson 不适用于虚拟主机

string - 存储字符串的内存有效方式

javascript - IIS Rewrite 在刷新时丢失 Angular 应用程序中的路径

使用 barba.js 进行页面转换后,JavaScript 文件不加载

javascript - 如何通过 d3.json 从 S3 下载 json 文件

c# - 需要经过排序的字典,旨在查找键小于或大于搜索值的值

c - C 中的内存压缩器?