Home > database >  How I create cloud firestore index? flutter
How I create cloud firestore index? flutter

Time:01-07

Hello everyone I want to create cloud firestore index to my firestore project and I don't know what stream should I upload to index field because I got error in the app that say:

W/Firestore(17047): (24.0.0) [Firestore]: Listen for Query(target=Query(chatRooms where participants.null == true order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
W/Firestore(17047): (24.0.0) [Firestore]: Listen for Query(target=Query(users/2e5yO3ZYKDWprC8dVi1bzlY9a0Q2 order by __name__);

And this is my streams:

QuerySnapshot snapshot = await _fireStore
        .collection("chatRooms")
        .where("participants.${userModel.uid}", isEqualTo: true)
        .where("participants.${targetUser.uid}", isEqualTo: true)
        .get();
StreamBuilder(
                    stream: _fireStore
                        .collection('chatRooms')
                        .doc(chatRoom.chatRoomId)
                        .collection('messages')
                        .orderBy('createdon', descending: true)
                        .snapshots(),

I can't post image because need at least 10 reputation

Rules:

Rules

CodePudding user response:

The easiest solution is to use the error message that includes a direct link to create the missing index in the Firebase console.

As explained here in the doc, "If you attempt a compound query with a range clause that doesn't map to an existing index, you receive an error".

So, catch the error in your code (normally with if (snapshot.hasError), see here in the FlutterFire doc), get the message and open the link in your preferred browser (with being logged to your Firebase project).


Other solutions are listed in the doc page referred to above, but again, with the link in the error message it's really easy!

  •  Tags:  
  • Related