In this project, I have image details stored in a map, within an array (imageUrls) in Firestore. I'm trying to query for the map that contains a specific imageName, then delete that map. My console isn't throwing any errors, and I've confirmed my Firestore rules are read & write.
Here's what my database looks like.
(https://i.stack.imgur.com/2UZpL.png)
And my corresponding code.
@override
Future<void> deleteUserPictures(User user, String imageName) async {
try {
var userImagesCollection = await _firebaseFirestore
.collection('users')
.doc(user.id)
.collection('imageUrls')
.where('imageName', isEqualTo: imageName)
.get();
// Loop through the documents that match the query
for (var docSnapshot in userImagesCollection.docs) {
// Delete the document
await docSnapshot.reference.delete();
}
} catch (e) {
print('Error deleting image: $e');
throw e;
}
}
Thanks in advance for any help!