【问题标题】:Firestore features and limitations on different data structure modelFirestore 对不同数据结构模型的特性和限制
【发布时间】:2018-03-29 18:29:58
【问题描述】:

我创建的应用程序的结构如下所示。当前结构仅适用于一家公司。

let current = {
    products: {
        product1: {}//...
    },
    customers: {
        customer1: {},// ...
    },
    orders: {
        order1: {},// ...
    },
}

现在我设计了数据结构,使其成为多公司应用程序。假设公司是ABCPQRXYZ,但客户是相同的。因此,客户可以看到来自不同公司的产品

选项 1:在每个列表文档中添加公司属性。

let option1 = {
    company: {
        products: {
            product1: {
                company: 'ABC'
            },
        },
        customers: { //Also we can put it at root with field company as array. Customers are not primary concern
            customer1: {
                company: 'PQR'
            }
        },
        orders: {
            order1: {
                company: 'ABC'
            }
        },
    }
}

我的评论:我必须将公司财产放在每个可能比这些更多的列表中。它看起来不像是正确的解决方案。查询不同公司的产品看起来很容易。

选项 2:复制不同公司的当前根结构。

let option2 = {
        company1: {
            products: {
                product1: {}
            },
            customers: {//Also we can put it at root with field company as array. Customers are not primary concern
                customer1: {},
            },
            orders: {
                order1: {},
            },
        },
        company2: {
            products: {
                product1: {}
            },
            customers: {
                customer1: {},
            },
            orders: {
                order1: {},
            },
        },
        // ...
    }

我的评论:我不知道 Firestore 的限制和即将推出的功能。查询不同公司的产品可能并不容易。

let option3= {} //your suggestions.

在同一个 Firestore 项目中,假设客户处理不会有问题。

这里可以做什么?我缺少什么?

【问题讨论】:

    标签: firebase data-structures firebase-realtime-database google-cloud-firestore


    【解决方案1】:

    产品

    很少有几家公司销售相同的产品,而不想创建自己的库存项目、描述、价格等。此外,如果您有销售该产品的公司的数组/地图,请在产品文档中,客户将看到他们可以在哪里购买产品,并且可能对任何一家公司都没有忠诚度。如果这是您希望实现的目标,那么您的选择可能对您有用。

    客户

    公司还希望将有关其客户的某些数据与其他公司分开。

    我的建议

    我建议您创建一个 Cloud Firestore 集合 companies 并为每个公司创建一个文档。在该文档中,您可以为customersordersproducts 创建子集合。

    根级别的单独users 集合将允许用户维护自己的数据,并允许公司收集他们需要的任何内容以保持其记录的最新状态。添加用户数据的公共和私有子集合可以为您轻松管理。

    来自 Firebase 团队的 Todd Kerpelman 制作了 an excellent video,这将真正有助于在 Cloud Firestore 中进行数据建模。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 2019-06-09
      • 1970-01-01
      • 2020-07-04
      • 2017-12-11
      • 2022-01-21
      • 2020-01-22
      相关资源
      最近更新 更多