Firebase Firestore Tutorial #7 - Ordering Data
Key Takeaways
Orders data in a Firebase Firestore project
Full Transcript
alright then so a super quick lesson here just to show you one extra method we can use when we're retrieving data and that is a method which is going to order our data for us because right now when we retrieve our data we're not displaying them or retrieving them in any kind of sensible order there's no order to them it's not alphabetical or date order etc so I'm gonna show you how we can actually order these alphabetically or by location or something like that so over here when we grab a reference to this Cuffy's collection like we added the wear method before instead what we can do now is add a different method it's called order by and what we can do is order by a specific property inside our data so we've got two properties we have name and we also have city so let's order by name first of all and that's gonna order them alphabetically by their name so let's save that and now we can see we have Donkey Kong first then Mario Rio swl now Luigi's Mansion is lowercase which is why it's coming after all of these things right here but if it was upper case it would be further up after D before the M now in firebase of firestore capital M s or capital letters rather come before lowercase letters so let me delete this and just add it in with capitals so there's no confusion so Luigi's Mansion and then this is somewhere spooky all right so let's add that and then what we'll do is just refresh the page so now we can see Luigi's Mansion is right there in alphabetical order cool so let's now try ordering them by the city instead so we'll say order by city save that and view that in a browser so now we can see alphabetically we're getting these back by city now London first then Manchester then New York then somewhere spooky awesome so this is a really simple way to order our data when we're retrieving it now we can also tack on a wear method as well before this we could say don't wear and then we'll say city is gonna be equal to and it's gonna be Manchester and then we'll order by name so we're getting everything where the city is equal to Manchester then were ordering those records all those documents by the name property alphabetically so let's see this and this time we get nothing because we have this error right here hmm so it's saying now that this query requires an index and sometimes when you first try to order a specific reference or collection of documents in a certain way it might throw this error up and it's because firebase requires you to create an index for this order of documents and you can very simply create that index just by clicking on this link that's all there is to it and that's going to take you to your firebase console and it's going to create this index for you so we can create it right here like so and that's building the index and then hopefully in a minute we should be able to refresh this page over here and then it will work as soon as this says done all rather than so now that index has been enabled what we can do is refresh over here and it should work okay so now we're getting that the bots in Manchester and they're being ordered alphabetically by the name so sometimes when we're performing these complex queries where we have where and odd by and requiring different things like this then we're going to be required to set up these indexes inside firestore now we just saw this link in the console that took us directly to the page to do that so you don't need to worry too much about creating those indexes yourself whenever you need one it's going to let you know right here in the console and you can just click on that link but there we go that's how we can order our data by different properties inside our documents
Original Description
Hey gang, in this Firebase Firestore tutorial I'll show you how we can use the orderBy method to order our data before we retrieve it. I'll also discuss indexes a little.
🐱💻 Course Links:
- VS Code editor - https://code.visualstudio.com/
- GitHub repository (course files) - https://github.com/iamshaunjp/firebase-firestore-playlist
- JavaScript DOM tutorial - https://www.youtube.com/watch?v=FIORjGvT0kk&list=PL4cUxeGkcC9gfoKa5la9dsdCNpuey2s-V
🤑 Donate @ https://www.paypal.me/thenetninja
🎓Find me on Udemy @ https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI