Advanced Firebase Data Filtering (Multi-Property)

Fireship · Advanced ·📊 Data Analytics & Business Intelligence ·8y ago

Key Takeaways

This video teaches strategies for filtering data in Firebase with multiple properties using Angular 4.3

Full Transcript

filtering data is one of the more difficult aspects of working with Firebase in this episode I'm going to cover four different techniques that you can use to filter data by multiple values at the same time the goal is to achieve similar results to what you would expect by using the wear claws in a SQL database in this app we have a collection of animals and we want to be able to filter these animals by three different attributes at the same time we want to filter by an exact string match for the family for a weight range for the animal's weight and a Boolean value for whether or not the animal is endangered in the database we just have a collection of animals and each animal has the properties that we want to filter by if you've worked with angular Fire 2 you're probably used to making queries like this where you return a Firebase list observable and pass a query to sort by a certain value this works great when you want to filter by just one single value but if you have multiple values you have to take a different approach the best option is to filter the list client side that is after you've received the data from Firebase the main drawback is that you have to load the entire collection into memory which may not work for larger data sets in this example I'm going to create a client side filtering system that allows you to add and remove various filtering rules to your data start by importing the angular fire database and we're also going to make extensive use of low Dash in this example we set a variable for animals which will always be the full data set pulled from Firebase and fil animals will be a copy of it with the filter rules applied to it this allows us to add and remove filters on the Fly next we set some variables for the attributes that we want to filter then we create another object that will keep track of the active filters applied to the data set during NG on a knit we return the Firebase list observable And subscribe to it and the value that it emits will be the animals variable and then we apply any active filters to it this allows us to keep the database insane in real time the next step is to actually filter the data we do this using the low Dash filter function first we pass it the full data set and then we use another low Dash function called conforms conforms takes an entire object of functions that return either true or false this allows us to filter multiple attributes at the same time check out the full lesson Link in the description if you want more detail than that from there we can create our first filter I want to make these as reusable as possible so I pass a property is an argument and a rule which is the value that that property must conform to in this app every animal has a family property so we can pass it that property and then set the rule to bird and that'll return all the birds in the collection we can add any filters of any degree of complexity using this technique in this example we filter all the values that are greater than the rule you can add any logic to this function it just has to return true or false in this app we're using it to filter the weight weight property on animals greater than a certain threshold and the last filter we're going to set up is a Boolean filter this one operates a little bit different because if it's false we want to remove the filter altogether and if it's true we can just return true to remove a filter all we have to do is delete that property from the filter's object now let's see how we have everything wired up in the HTML we start by creating a select box and bind that to NG model and our family variable and that typescript then we can call the filter exact method passing it the family property as well as the family variable that's being set by NG model to remove a filter we just see if that family variable is defined and if so we allow the user to click a button that runs the remove filter method for the weight greater than we follow the same basic process just passing it a different variable and different property name at this point you might notice how these filter methods can be reused on any infinite number of properties and to to show the animals all we have to do is Loop over the filtered animals variable now when we go back to the app we have a basic client side filtering system all set up so what if your data set is too large for client side filtering the next option would be to create composite Keys the idea behind this is to combine multiple key value pairs into a single key value pair the main drawback is that it's only really practical for up to three properties after that you'll have way too many key value combinations to keep track of if we were to implement this in our app this is how the composite Keys would look in the database we would combine the keys and then combine their values allowing us in an indirect way to query for multiple properties at once then we could use these keys to query the database with angular Fire 2 just like normal if you think this is the right approach for your app there's also a library called query base that does this for you automatically it's experimental at this point but might be something to look into another another way to filter by multiple attributes in Firebase is to use a tag filtering strategy in this case you would denormalize your data to keep track of each item under a tag that it's associated with this would allow you to pull all the items associated with a specific tag and then combine them together you could either take the intersection or the union of those keys and then make a query for each item individually you could use the intersection helper from low Dash and then make requests for Fire based object observables based on the keys that are returned and the last option I'm going to talk about is using a third party service such as algolia or elastic search I made a couple videos recently about using algolia with angular 4 and Firebase and if you're doing a lot of advanced filtering of your data it's usually a good idea to Outsource this to a third party service data indexing is a rather high maintenance and error prone process so mess around with third party providers before trying to do the entire thing from scratch that's it for advanced filtering with fire base if this video helped you please like And subscribe and consider joining our slack team if you want to discuss this in more detail and if you want to support the channel become a pro member at angular firebase.com for a free copy of my book as well as one-on-one project Consulting thanks for watching and I'll see you [Music] soon

Original Description

In this episode I provide strategies for filtering data in Firebase with multiple properties or attributes, similar to a SQL where clause. Client-side filtering is performed with Angular 4.3. Check out the full lesson: https://angularfirebase.com/lessons/multi-property-data-filtering-with-firebase-and-angular-4/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Fireship · Fireship · 32 of 60

1 Angular 4 Development and Production Environments with Firebase
Angular 4 Development and Production Environments with Firebase
Fireship
2 OAuth with Angular and Firebase Tutorial
OAuth with Angular and Firebase Tutorial
Fireship
3 Anonymous Authentication with Angular and Firebase - Lazy Registration
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
4 Angular Router Guards for Firebase Users
Angular Router Guards for Firebase Users
Fireship
5 Angular Firebase CRUD App with NoSQL Database Tutorial
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
6 Upload Files from Angular to Firebase Storage
Upload Files from Angular to Firebase Storage
Fireship
7 How to Deploy an Angular App to Firebase Hosting
How to Deploy an Angular App to Firebase Hosting
Fireship
8 Sharing Data between Components in Angular
Sharing Data between Components in Angular
Fireship
9 Loading Spinners for Asynchronous Firebase Data
Loading Spinners for Asynchronous Firebase Data
Fireship
10 Angular 4 Transactional Email with Google Firebase Cloud Functions
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
11 Firebase Database Rules Tutorial
Firebase Database Rules Tutorial
Fireship
12 Autocomplete Search with Angular4 and Firebase
Autocomplete Search with Angular4 and Firebase
Fireship
13 Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
14 Angular Drag-and-Drop File Uploads to Firebase Storage
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
15 Text Translation with Firebase Cloud Functions onWrite and Angular 4
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
16 Custom Usernames with Firebase Authentication
Custom Usernames with Firebase Authentication
Fireship
17 Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
18 Simple Pagination with Firebase and Angular 4
Simple Pagination with Firebase and Angular 4
Fireship
19 How to Connect Firebase Users to their Data - 3 Methods
How to Connect Firebase Users to their Data - 3 Methods
Fireship
20 Add Toast Message Notifications to your Angular App
Add Toast Message Notifications to your Angular App
Fireship
21 Facebook-Inspired Reactions System with Angular and Firebase
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
22 Learn NgModule in Angular with Examples
Learn NgModule in Angular with Examples
Fireship
23 Lazy Loading Components in Angular 4
Lazy Loading Components in Angular 4
Fireship
24 Stripe Checkout Payments with Angular and Firebase - Part 1
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
25 Process Stripe Payments with Firebase Cloud Functions - Part 2
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
26 Selling Digital Content in Angular with Stripe Payments - Part 3
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
27 Angular 4 Full Text Search with Algolia - Part 1
Angular 4 Full Text Search with Algolia - Part 1
Fireship
28 Algolia with Firebase Cloud Functions - Part 2
Algolia with Firebase Cloud Functions - Part 2
Fireship
29 Firebase Phone Authentication in Angular 4
Firebase Phone Authentication in Angular 4
Fireship
30 Top 7 RxJS Concepts for Angular Developers
Top 7 RxJS Concepts for Angular Developers
Fireship
31 Learn Angular Animations with 5 Examples
Learn Angular Animations with 5 Examples
Fireship
Advanced Firebase Data Filtering (Multi-Property)
Advanced Firebase Data Filtering (Multi-Property)
Fireship
33 Realtime Maps with Mapbox + Firebase + Angular
Realtime Maps with Mapbox + Firebase + Angular
Fireship
34 Angular Reactive Forms with Firebase Database Backend
Angular Reactive Forms with Firebase Database Backend
Fireship
35 Send Push Notifications in Angular with Firebase Cloud Messaging
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
36 Top 7 Ways to Debug Angular 4 Apps
Top 7 Ways to Debug Angular 4 Apps
Fireship
37 Infinite Scroll with Angular and Firebase
Infinite Scroll with Angular and Firebase
Fireship
38 Use TypeScript with Firebase Cloud Functions
Use TypeScript with Firebase Cloud Functions
Fireship
39 Realtime Graphs and Charts with Plotly and Firebase
Realtime Graphs and Charts with Plotly and Firebase
Fireship
40 Role-Based User Permissions in Firebase
Role-Based User Permissions in Firebase
Fireship
41 User Presence System in Realtime - Online, Offline, Away
User Presence System in Realtime - Online, Offline, Away
Fireship
42 Location-based Queries with GeoFire and Angular Google Maps
Location-based Queries with GeoFire and Angular Google Maps
Fireship
43 Angular ngrx Redux Quick Start Tutorial
Angular ngrx Redux Quick Start Tutorial
Fireship
44 Angular Ngrx Effects with Firebase Database
Angular Ngrx Effects with Firebase Database
Fireship
45 Progressive Web Apps with Angular
Progressive Web Apps with Angular
Fireship
46 Angular Ngrx with Firebase Google OAuth User Authentication
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
47 RxJS Quick Start with Practical Examples
RxJS Quick Start with Practical Examples
Fireship
48 Send SMS Text Messages with Twilio and Firebase
Send SMS Text Messages with Twilio and Firebase
Fireship
49 Firebase Database Performance Profiling
Firebase Database Performance Profiling
Fireship
50 Native Desktop Apps with Angular and Electron
Native Desktop Apps with Angular and Electron
Fireship
51 Subscription Payments with Stripe, Angular, and Firebase
Subscription Payments with Stripe, Angular, and Firebase
Fireship
52 Firestore with AngularFire5 Quick Start Tutorial
Firestore with AngularFire5 Quick Start Tutorial
Fireship
53 Angular HTTP Client Quick Start Tutorial
Angular HTTP Client Quick Start Tutorial
Fireship
54 Google Sign-In with Firestore Custom User Data
Google Sign-In with Firestore Custom User Data
Fireship
55 Star Review System from Scratch with Firestore + Angular
Star Review System from Scratch with Firestore + Angular
Fireship
56 Angular Chatbot with Dialogflow (API.ai)
Angular Chatbot with Dialogflow (API.ai)
Fireship
57 Learn @ngrx/entity and Feature Modules
Learn @ngrx/entity and Feature Modules
Fireship
58 Infinite Scroll Pagination with Firestore
Infinite Scroll Pagination with Firestore
Fireship
59 Faster Firestore via Data Aggregation
Faster Firestore via Data Aggregation
Fireship
60 Contentful - CMS for Angular Progressive Web Apps
Contentful - CMS for Angular Progressive Web Apps
Fireship

Related Reads

📰
Stop Testing One Indicator at a Time. Loop Your Way to Better Trading
Learn to improve trading by testing multiple indicators using a champion loop, increasing efficiency and accuracy in trading strategies
Medium · Data Science
📰
Fact Tables, Star Schemas, Joins and Dashboards
Learn to design efficient data models using fact tables, star schemas, and joins to create informative dashboards
Dev.to · samwel
📰
The Ultimate Step-by-Step Guide: Connecting Power BI to Cloud-Based & Local PostgreSQL
Learn to connect Power BI to PostgreSQL databases, both cloud-based and local, to unlock powerful data analysis and visualization capabilities
Dev.to · michael imani
📰
Understanding Data Warehousing: The Complete Beginner’s Guide for Data Engineering
Learn the basics of data warehousing and its importance in data engineering
Medium · Data Science
Up next
How to Hire Top SEO Talent
Menerva Digital
Watch →