Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

89
Views
Firestore sort by value

I'm trying to create a filter for my application It will filter by the datas' category, but I also want to sort them by its rating, higher rating will be on the top. I wrote the following code, but the orderby() function having issue.

        const snapshot = await firebase.firestore().collection('Locations').where(
            "category", "==", type).orderBy("rating").get();
        
        if (snapshot.empty){
            console.log('No matching documents');
            return;
        }
        
        snapshot.forEach(doc=> {
            locList.push(doc.data());
        })

and here is my firestore data look like firestore data

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

To sort values from largest rating to smallest rating, specify the ordering as descending. Change the orderBy function to:

.orderBy('rating', 'desc')

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.