Gino
Gino

Reputation: 176

Use where('x', arrayContainsAny: x) with orderBy Date

I'm trying to use

FirebaseFirestore.instance
          .collection('Jobs')
          .where('types', arrayContainsAny: selectedRooms)
          .orderBy('types', descending: true)
          .orderBy('date', descending: true)
          .limit(30)
          .get();

I've already checked

  1. How to use orderby with where(isNotEqualTo) in flutter Firestore
  2. How to use orderby with where(isNotEqualTo) in flutter Firestore
    but with no luck
    I've already created an index for
  1. types: asc
  2. date: asc

Update:

JobID: UID 
publisherName: String
Types: Array<String>
date: Timestamp
title: String
address: String

Any Help will be appreciated! Happy Coding

Upvotes: 0

Views: 52

Answers (1)

Gino
Gino

Reputation: 176

After several tries without success I've managed to solved this by using the

Firebase QueryBuilder

Basically what this does it shows a new type to use in the index which is Array Otherwise not selectable if you create the index by yourself. So the new Generated Index is

  1. types: Array
  2. date: asc

While keeping the same query as mentioned on the question this solved my problem.
Thanks to everybody!

Upvotes: 1

Related Questions