使用通配符作为路径的深度路径查询 [英] Deep path query using wildcard as a path

查看:25
本文介绍了使用通配符作为路径的深度路径查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据,其中我试图遵循 Firebase 关于扁平结构的建议,所以我不会拉出超过我需要的东西.最终结果是我在节点中组织了这样的引号:

I have data in which I've tried to follow Firebase's advice about flat structure so I'm not pulling more than I need. The net result is I have quotes organised in nodes like this:

quotes -> clientName -> quoteObject

quoteObjects 有一个 'dateCreated' 值,我希望能够像这样提取这些数据(因为当我提取特定页面的所有引号的一个大列表时,我然后使用对象分配来制作要显示的一大堆对象):

the quoteObjects have a 'dateCreated' value, and I want to be able to pull this data like so (for when I'm pulling one big list of all the quotes for a specific page, I then use object assign to make one big array of objects to display) :

  const quotesRef = firebase.database().ref('quotes');
    quotesRef.orderByChild('dateCreated').on('value', snapshot => {
       // function
    });

不幸的是,dateCreated 值的深度不止一层,因此标准查询不起作用.我知道如果您知道父路径,则可以进行深度路径查询,但在我的情况下,clientName 父级始终是唯一的.鉴于此,是否可以指定一种通配符路径?如果是这样,我将如何处理?干杯!

Unfortunately the dateCreated value is more than one level deep so the standard query doesn't work. I know you can do a deep path query if you know the parent path, but in my case the clientName parent is always unique. Given this, is it possible to specify a kind of wildcard path? If so how would I go about that? Cheers!

显示数据库示例,抱歉,最初应该更具体.

Showing database example, sorry should have been more specific initially.

quotes
    - ClientEmailOne
        -UniqueQuoteID
            - createdBy: ClientEmailOne
            - dateCreated: 1479255005172
            - email: "clientsEmail@example.com"
    - ClientEmailTwo
        -UniqueQuoteID
            - createdBy: ClientEmailTwo
            - dateCreated: 1479255005172
            - email: "clientsEmail@example.com"
     - ClientEmailThree
         -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "clientsEmail@example.com"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "clientsEmail@example.com"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "clientsEmail@example.com"

推荐答案

Firebase 会考虑您运行查询所在位置的子级.您指定要对其进行排序/过滤的子项可以包含属性的路径,但它不能包含任何通配符.

Firebase will consider children of the location you run the query on. The child you specify to order/filter on can contain a path to a property, but it cannot contain any wildcards.

更新:

使用您的新数据结构,您似乎正在尝试跨所有客户以及每个客户的所有报价进行查询.那里有两个通配符(所有客户端"和所有引号"),这是 Firebase 的查询模型不允许的.

With your new data structure it seems that you're trying to query across all clients and across all quotes of each of these clients. There are two wildcards in there ("all clients" and "all quotes" under that), which Firebase's querying model doesn't allow.

您当前的模型允许查询特定客户的所有报价:

Your current model allows querying all quotes for a specific client:

ref.child("quotes").child("ClientEmailOne").orderByChild("dateCreated")

如果你想查询所有客户的所有报价,你需要添加一个包含所有报价的数据结构(不管他们的客户):

If you want to query all quotes across all clients, you'll need to add a data structure that contains all quotes (irrespective of their client):

allquotes
    -UniqueQuoteID
        - createdBy: ClientEmailOne
        - dateCreated: 1479255005172
        - email: "clientsEmail@example.com"
    -UniqueQuoteID
        - createdBy: ClientEmailTwo
        - dateCreated: 1479255005172
        - email: "clientsEmail@example.com"
     -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "clientsEmail@example.com"
    -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "clientsEmail@example.com"
    -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "clientsEmail@example.com"

然后就可以查询了:

ref.child("allquotes").orderByChild("dateCreated")

这篇关于使用通配符作为路径的深度路径查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆