Shamoon
Shamoon

Reputation: 43617

orderBy with react-firebase-hooks/firestore not working

I'm using react-firebase-hooks/firestore

and I have:

  const [documents, documentsLoading, documentsError]: [DocumentInterface[], boolean, Error] = useCollectionDataOnce(
    firebase.firestore().collection('documents')
      .where('userId', '==', firebase.auth()?.currentUser?.uid || null)
      .orderBy('updatedAt')
    ,
    { idField: 'id' }
  )

which returns no results. If I remove the .orderBy('updatedAt'), then I have results. Why would that be?

Upvotes: 0

Views: 498

Answers (1)

Nicholas Harder
Nicholas Harder

Reputation: 1558

This query requires a composite index. If you check the console, the error will include a link that will automatically create it for you.

Upvotes: 2

Related Questions