Search code examples
swiftgoogle-cloud-firestorefirebase-console

The query requires an index. You can create it here: {link is broken}


I'm querying against my "GroupConvos" collection where the documents all have a memberIds string array with Ids about members that belong to that group and doing the following query for GroupConvos gives me with a broken link

self.db.collection(kGroupConvos)
       .order(by: kUpdatedAt, descending: true)
       .whereField("memberIds", arrayContains: self.currentUserId)
       .limit(to: 20)
       .getDocuments { [weak self] snapshot, error in
            if let error = error {
               print(error) 
            } else { ... }

The query requires an index. You can create it here: {link}

Image:

enter image description here

So I went into the console and created an index:

enter image description here

And I keep getting that same error when I do my query. Any suggestions as to what to do here?


Solution

  • If you're using array-contains to search a field, it looks like you need to add an Array Contains type index to it:

    enter image description here

    Notice that you have an option for that. It looks like what you did instead was make memberIds an Ascending type field index.