Fireship · @fireship
Advanced Firebase Data Filtering (Multi-Property)
Uploaded July 26, 2017 · Length 6:28
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.
- 0:00
filtering data is one of the more
- 0:02
difficult aspects of working with
- 0:03
Firebase in this episode I'm going to
- 0:05
cover four different techniques that you
- 0:07
can use to filter data by multiple
- 0:09
values at the same time the goal is to
- 0:12
achieve similar results to what you
- 0:14
would expect by using the wear claws in
- 0:16
a SQL database in this app we have a
- 0:19
collection of animals and we want to be
- 0:21
able to filter these animals by three
- 0:22
different attributes at the same time we
- 0:25
want to filter by an exact string match
- 0:27
for the family for a weight range for
- 0:29
the animal's weight and a Boolean value
- 0:32
for whether or not the animal is
- 0:34
endangered in the database we just have
- 0:36
a collection of animals and each animal
- 0:38
has the properties that we want to
- 0:40
filter
- 0:41
by if you've worked with angular Fire 2
- 0:43
you're probably used to making queries
- 0:45
like this where you return a Firebase
- 0:47
list observable and pass a query to sort
- 0:49
by a certain
- 0:51
value this works great when you want to
- 0:52
filter by just one single value but if
- 0:55
you have multiple values you have to
- 0:56
take a different approach the best
- 0:58
option is to filter the list client side
- 1:00
that is after you've received the data
- 1:02
from Firebase the main drawback is that
- 1:04
you have to load the entire collection
- 1:05
into memory which may not work for
- 1:08
larger data sets in this example I'm
- 1:10
going to create a client side filtering
- 1:12
system that allows you to add and remove
- 1:15
various filtering rules to your data
- 1:17
start by importing the angular fire
- 1:19
database and we're also going to make
- 1:21
extensive use of low Dash in this
- 1:23
example we set a variable for animals
- 1:26
which will always be the full data set
- 1:27
pulled from Firebase and fil animals
- 1:30
will be a copy of it with the filter
- 1:32
rules applied to it this allows us to
- 1:34
add and remove filters on the Fly next
- 1:37
we set some variables for the attributes
- 1:40
that we want to filter then we create
- 1:42
another object that will keep track of
- 1:43
the active filters applied to the data
- 1:46
set during NG on a knit we return the
- 1:48
Firebase list observable And subscribe
- 1:51
to it and the value that it emits will
- 1:54
be the animals variable and then we
- 1:56
apply any active filters to it this
- 1:58
allows us to keep the database insane in


