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:
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.
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:However
cloud_firestore_odm
doesn't give you an option to do it. If you useset()
you can't useFieldValue
. If you useupdate()
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
update()
, e.gbool forceCreate
, which will create the doc if it doesn't exist instead of throwing.