I am facing a delete/update issue with firestore array object.This is my subcollection looks like
I have an option in my flutter web app
to delete or update the questions.
questionnaire
is an array and all the indexes are map
.
Is there any possible way to delete or update the indexes directly? I have seen a couple of solutions where all the array elements are read back to the application and remove the item we need to delete and add the items that need to be updated. I will be having around 150 questions in an array, so I think it is not an efficient way from a performance point of view. So I have tried couple of methods to delete the data
FirebaseFirestore.instance
.collection('exam')
.doc(examDocID)
.collection('questionnaire')
.doc(_questionnaireDocID)
.update({
'questionnaire': {'$index': FieldValue.delete()}
}).then((_) {
print('question deleted');
}).catchError((onError) {
print(onError);
});
and
'questionnaire.$index': FieldValue.delete()
'questionnaire': FieldValue.arrayRemove([index])
It used to delete all elements in the array from most of my tries. Could someone please let me know is there any workaround to fix this issue