Firebase - Get All Data That Contains

后端 未结 1 990
悲哀的现实
悲哀的现实 2020-12-12 02:20

I have a firebase model where each object looks like this:

done: boolean
|
tags: array
|
text: string

Each object\'s tag array

相关标签:
1条回答
  • 2020-12-12 03:12

    Many of the more common search scenarios, such as searching by attribute (as your tag array would contain) will be baked into Firebase as the API continues to expand.

    In the mean time, it's certainly possible to grow your own. One approach, based on your question, would be to simply "index" the list of tags with a list of records that match:

    /tags/$tag/record_ids...
    

    Then to search for records containing a given tag, you just do a quick query against the tags list:

    new Firebase('URL/tags/'+tagName).once('value', function(snap) {
        var listOfRecordIds = snap.val();
    });
    

    This is a pretty common NoSQL mantra--put more effort into the initial write to make reads easy later. It's also a common denormalization approach (and one most SQL database use internally, on a much more sophisticated level).

    Also see the post Frank mentioned as that will help you expand into more advanced search topics.

    0 讨论(0)
提交回复
热议问题