firestoreodm-flutter
firestoreodm-flutter copied to clipboard
Feature request - support FieldValues in set()
Scenario
Let's say you have a reference to a document and you want to either create the doc if it doesn't exist or update it (including deleting a field in it) if it does exist. With the original cloud_firestore
sdk you could do:
FirebaseFirestore.instance.doc('path_to_doc').set(
{
'fieldToUpdate': 'New value',
'fieldToRemove': FieldValue.delete(),
},
SetOptions(merge: true),
);
However cloud_firestore_odm
doesn't give you an option to do it. If you use set()
you can't use FieldValue
. If you use update()
and the doc doesn't exist it will fail.
I also don't want to use the transaction API because it doesn't have the offline capabilities and immediate responses which are important for user experience.
Possible solution ideas
- Create another method, e.g
setFieldValues(
FieldValue? fieldToUpdateFieldValue,
FieldValue? fieldToRemoveFieldValue,
)
- Add a parameter to method
update()
, e.gbool forceCreate
, which will create the doc if it doesn't exist instead of throwing.