'When sorting by multiple fields in Firestore with startAt and endAt not working correctly

I am doing a document filter functionality.

The problem is that when I receive a filter for the "max_players" and "name" fields, it returns an empty array when there are documents that meet the conditions.

The error occurs when doing startAt and endAt when there is more than one OrderBy and I don't understand the reason.

Technologies:

  • Angular
  • Firebase - Firestore

Service:

if (filter.players != null) {
      const option: string = filter.players.substring(0, 1);

      if (option == '+') {
        ref = ref.where('max_players', '>=', 8)
      } else {
        const num_players: number = parseInt(option);
        ref = ref.where('max_players', '>=', num_players)
      }
    }

if (filter.text != null) {
  if (filter.players != null) {
    ref = ref.orderBy('max_players').orderBy('name').startAt(filter.text).endAt(filter.text + '\uf8ff');
  }else{
    ref = ref.orderBy('name').startAt(filter.text).endAt(filter.text + '\uf8ff');
  }
}


Solution 1:[1]

Firebase limitation

Documentation: https://github.com/firebase/firebase-js-sdk/issues/2577#

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JuamBer