Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase Firestore的复杂数据模型_Firebase_Data Modeling_Google Cloud Firestore - Fatal编程技术网

Firebase Firestore的复杂数据模型

Firebase Firestore的复杂数据模型,firebase,data-modeling,google-cloud-firestore,Firebase,Data Modeling,Google Cloud Firestore,我正在用Firestore+angularfire构建我的第一个应用程序,由于我缺乏Firestore的经验,很难定义数据模型。我需要你的帮助 我有以下实体和依赖项 餐厅:它们是独立的,可以由应用程序的用户注册 创建餐厅的用户成为“所有者”。他/她可以邀请其他用户成为餐厅的“服务员/服务员” 用户可以收到来自一家或多家餐厅(可能来自不同的店主)的“做我的服务员/服务员”邀请 我们还有另一个“客户”实体。该实体的条目包含有关订购的菜肴和饮料、价格、小费等的数据 然后是以下规则 每位店主都可以在其餐

我正在用Firestore+angularfire构建我的第一个应用程序,由于我缺乏Firestore的经验,很难定义数据模型。我需要你的帮助

我有以下实体和依赖项

  • 餐厅:它们是独立的,可以由应用程序的用户注册
  • 创建餐厅的用户成为“所有者”。他/她可以邀请其他用户成为餐厅的“服务员/服务员”
  • 用户可以收到来自一家或多家餐厅(可能来自不同的店主)的“做我的服务员/服务员”邀请
  • 我们还有另一个“客户”实体。该实体的条目包含有关订购的菜肴和饮料、价格、小费等的数据
  • 然后是以下规则

  • 每位店主都可以在其餐厅中看到任何“客户”数据,但在其他餐厅中看不到
  • 每个“服务员/服务员”都可以看到他/她服务的顾客的数据(在任何餐馆),但不能看到其他顾客的数据
  • 因此,正如您所看到的,Firestore中的“where”过滤器不支持多个依赖项,包括多个OR条件。因此,我不确定是应该将客户集合嵌套到每个餐厅文档中,还是应该将所有客户都放在根集合中,然后对其进行过滤


    您能帮我解决这个问题,并提供一些您认为使用Firestore规则管理它的最佳方式的想法吗???

    这是一个基于您所说的建议:

    Restaurants
        [id] (document)
            owner: idUser(Owner)
            waiters (map)
                idUser1: timestamp
                idUser2: timestamp
                idUser3: timestamp
            customersIn (collection)
                [idCustomer1] 
                    itens: (map)
                        french fries: 10
                        water: 3
                [idCustomer2]
                    itens: (map)
                        hot dog: 6
                        soda: 4
    Customers
        [id] (document)
            name
            restaurants (map)
                idRestaurant1: timestamp
                idRestaurant2: timestamp
    Users
        [id] (document)
            waiterIn (map)
                idRestaurant1: timestamp
                idRestaurant2: timestamp
    
    当您尝试对其进行筛选和排序时,此aproach在中被注释

    在这种情况下,你可以像餐厅的顾客、一家餐厅的服务员或服务员所在的餐厅那样提出任何疑问。 像这样:

    customersRef.where("restaurants." + idRestaurant, '>', 0).orderBy("restaurants." + idRestaurant);
    
    希望这有帮助