I wrote the following code. However, when I run it, it does not work. I am probably not able to get the document ID. sorry,Please let me know if there are any modifications to my code.
Future<void> deleteRoom() async {
//Put the ID of the document to be deleted in the list
List deleteRoomIdList = [];
//The ID of the document to be deleted is placed here in a for statement.
String deleteId;
FirebaseFirestore.instance
.collection('room')
.where('roomCount', whereIn: [0, null])
.get()
.then((QuerySnapshot querySnapshot) => {
querySnapshot.docs.forEach(
(doc) {
deleteRoomIdList.add(doc.id);
},
),
});
//Deleting with a for statement
for (deleteId in deleteRoomIdList) {
await FirebaseFirestore.instance
.collection('room')
.doc(deleteId)
.delete();
}
}