Fireship · @fireship

Advanced Firebase Data Filtering (Multi-Property)

Uploaded July 26, 2017 · Length 6:28

Advanced Firebase Data Filtering (Multi-Property)

Summary

Learn four techniques to filter Firebase data by multiple values: client-side filtering, composite keys, tag filtering, and using a third-party service like Algolia.

  • firebase data filtering
  • advanced firebase filtering
  • firebase multi-property filtering
  • firebase client-side filtering
  • firebase composite keys
  • firebase tag filtering
  • firebase algolia integration

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    filtering data is one of the more

  2. 0:02

    difficult aspects of working with

  3. 0:03

    Firebase in this episode I'm going to

  4. 0:05

    cover four different techniques that you

  5. 0:07

    can use to filter data by multiple

  6. 0:09

    values at the same time the goal is to

  7. 0:12

    achieve similar results to what you

  8. 0:14

    would expect by using the wear claws in

  9. 0:16

    a SQL database in this app we have a

  10. 0:19

    collection of animals and we want to be

  11. 0:21

    able to filter these animals by three

  12. 0:22

    different attributes at the same time we

  13. 0:25

    want to filter by an exact string match

  14. 0:27

    for the family for a weight range for

  15. 0:29

    the animal's weight and a Boolean value

  16. 0:32

    for whether or not the animal is

  17. 0:34

    endangered in the database we just have

  18. 0:36

    a collection of animals and each animal

  19. 0:38

    has the properties that we want to

  20. 0:40

    filter

  21. 0:41

    by if you've worked with angular Fire 2

  22. 0:43

    you're probably used to making queries

  23. 0:45

    like this where you return a Firebase

  24. 0:47

    list observable and pass a query to sort

  25. 0:49

    by a certain

  26. 0:51

    value this works great when you want to

  27. 0:52

    filter by just one single value but if

  28. 0:55

    you have multiple values you have to

  29. 0:56

    take a different approach the best

  30. 0:58

    option is to filter the list client side

  31. 1:00

    that is after you've received the data

  32. 1:02

    from Firebase the main drawback is that

  33. 1:04

    you have to load the entire collection

  34. 1:05

    into memory which may not work for

  35. 1:08

    larger data sets in this example I'm

  36. 1:10

    going to create a client side filtering

  37. 1:12

    system that allows you to add and remove

  38. 1:15

    various filtering rules to your data

  39. 1:17

    start by importing the angular fire

  40. 1:19

    database and we're also going to make

  41. 1:21

    extensive use of low Dash in this

  42. 1:23

    example we set a variable for animals

  43. 1:26

    which will always be the full data set

  44. 1:27

    pulled from Firebase and fil animals

  45. 1:30

    will be a copy of it with the filter

  46. 1:32

    rules applied to it this allows us to

  47. 1:34

    add and remove filters on the Fly next

  48. 1:37

    we set some variables for the attributes

  49. 1:40

    that we want to filter then we create

  50. 1:42

    another object that will keep track of

  51. 1:43

    the active filters applied to the data

  52. 1:46

    set during NG on a knit we return the

  53. 1:48

    Firebase list observable And subscribe

  54. 1:51

    to it and the value that it emits will

  55. 1:54

    be the animals variable and then we

  56. 1:56

    apply any active filters to it this

  57. 1:58

    allows us to keep the database insane in