Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Multiple orderBy() in Firestore Query Produces Error

I want to query Firestore db and order by two fields. Official docs suggest I can simply combine the orderBy statements via orderBy('field1').orderBy('field2') but when I run similar code, I get the following error in console:

Project.js:62 Uncaught (in promise) TypeError: (0 , firebase_firestore__WEBPACK_IMPORTED_MODULE_0__.orderBy)(...).orderBy is not a function

My code:

const projectRef = doc(db, 'projects', projectId)
const docSnap = await getDoc(projectRef)

if(docSnap.exists()) {
    const imagesInfoRef = collection(db, 'projectGalleryImages')
    const imagesInfoDocsSnapshot = await getDocs(query(imagesInfoRef, where('project', '==', projectRef), orderBy('displayOrder').orderBy('createdOn')))
    imagesInfoDocsSnapshot.docs.map(imageInfo => {
        const imageRef = ref(storage, `project/${projectId}/images/${imageInfo.fileName}`)
        loadImageURL(imageRef)
    })
}

Why am I getting this error?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

You're mixing the older namespaced syntax with the newer modular syntax. In the latter, each orderBy call is a standalone instruction:

query(imagesInfoRef, 
  where('project', '==', projectRef),
  orderBy('displayOrder'), // ๐Ÿ‘ˆ comma here, instead of a dot
  orderBy('createdOn')
)
about 4 years 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 vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!