hamburger-tech-nits

主にプログラミングのNITSな話

`[cloud_firestore/failed-precondition] Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console`

FlutterでFirestoreのcollection_groupにwhere条件を設定したクエリを実行したところ、[cloud_firestore/failed-precondition] Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console.というエラーメッセージが表示された。

どうも必要なインデックスが設定されていないために発生しているエラーの模様。しかし、この情報だけでは何のインデックスが足りていないのかわからない。そこで、Firebaseのコンソールにアクセスしクエリビルダーで同じクエリを実行してみた。

出力された別のエラーメッセージにはインデックス作成用ページのリンクも含まれていた。そのリンク先で必要なインデックスを追加作成したところ、無事クエリを実行できるようになった。