LoginSignup
2
0

More than 3 years have passed since last update.

Firestoreのドキュメントは、Where句では削除できません。

Posted at

Firestoreに散りばめられたテスト用データ たち
どうやって削除したら良いのか。
SQLみたいにWhereで指定して、それにDeleteメソッドつなければいけるんじゃないか?

こういうのがしたかった。

firebase.firestore().collection("projects").where("title","==","TITLE_TEST36").delete().then(() => {
        console.log("Document successfully deleted!");
    }).catch((error) => {
        console.log("Error removing document: ", error);
    });

どうやらダメらしい。

↓こんな感じにしたら、ちゃんとTITLE_TEST36を成仏させてくれた。

var ref = firebase
      .firestore()
      .collection("projects")
      .where("title", "==", "TITLE_TEST36");
    let batch = firebase.firestore().batch();

    ref.get().then((snapshot) => {
      snapshot.docs.forEach((doc) => {
        batch.delete(doc.ref);
      });
      return batch.commit();
    });
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0