javascript - Deep path query using wildcard as a path - Stack Overflow

I have data in which I've tried to follow Firebase's advice about flat structure so I'm

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

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
    });

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!

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

quotes
    - ClientEmailOne
        -UniqueQuoteID
            - createdBy: ClientEmailOne
            - dateCreated: 1479255005172
            - email: "[email protected]"
    - ClientEmailTwo
        -UniqueQuoteID
            - createdBy: ClientEmailTwo
            - dateCreated: 1479255005172
            - email: "[email protected]"
     - ClientEmailThree
         -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "[email protected]"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "[email protected]"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "[email protected]"

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

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
    });

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!

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

quotes
    - ClientEmailOne
        -UniqueQuoteID
            - createdBy: ClientEmailOne
            - dateCreated: 1479255005172
            - email: "[email protected]"
    - ClientEmailTwo
        -UniqueQuoteID
            - createdBy: ClientEmailTwo
            - dateCreated: 1479255005172
            - email: "[email protected]"
     - ClientEmailThree
         -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "[email protected]"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "[email protected]"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "[email protected]"
Share Improve this question edited Nov 16, 2016 at 3:25 Sam Matthews asked Nov 16, 2016 at 0:39 Sam MatthewsSam Matthews 6771 gold badge12 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

Update:

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: "[email protected]"
    -UniqueQuoteID
        - createdBy: ClientEmailTwo
        - dateCreated: 1479255005172
        - email: "[email protected]"
     -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "[email protected]"
    -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "[email protected]"
    -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "[email protected]"

Then you can query:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744065952a4552653.html

相关推荐

  • javascript - Deep path query using wildcard as a path - Stack Overflow

    I have data in which I've tried to follow Firebase's advice about flat structure so I'm

    9天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信