-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support preconditions in set()
#2087
Comments
I suppose another option: add a |
Hi @brettwillis , Could you please provide more context of the advantages or the use cases comparing Use and setDoc with precondition check? |
@cherylEnkidu thanks for your reply! Yes an atomic read-write (
So yes doing an atomic read-write is an option, just like doing |
@cherylEnkidu another use-case: Say one wants to do a deep merge, using atomic That is like so: // FIXME: we cannot enforce "exists" precondition with this API
ref.set({
counters: {
counter1: FieldValue.increment(1),
counter2: FieldValue.increment(-1),
// don't touch counter3..N
}
}, { merge: true }); The only way to do this currently is to awkwardly reshape the data into an array of key-value pairs to pass into the |
Hi @brettwillis , Thank you for providing the use case context! The team discussed this feature request, we think it is reasonable to support it but it may not get a relative high priority due to 2 reasons:
I have log b/357006681 to track the request internally, if any developer has more use cases, please feel free to reply to this github ticket, it will help us better prioritize feature requests. Thank you! |
Thanks @cherylEnkidu is this a case where community contribution would be accepted, or does it need to go through the core team due to API design? |
There is a bit of a gap in functionality between the
update()
andset()
APIs.set()
, we can control merging or full replacement of the document, but cannot control preconditions.update()
we can control preconditions, but cannot control merging (it always does a shallow merge).However, what if we want to to a complete replacement of the document (i.e.
set()
without merge) but enforce a precondition that the document must already exist?If one makes extensive use of
undefined
values and wants aexists: true
precondition, then one has no other choice but to useupdate()
and then must be very careful to replace all instances ofundefined
withFieldValue.delete()
.I would propose including the
lastUpdateTime
andexists
precondition fields in theSetOptions
so that we can apply preconditions on a set operation, e.g.:Subsequently, a minor win of then using
set(..., { exists: true })
instead ofupdate(...)
is saving the bandwidth and overhead of calculating and transmitting the field mask with the request to the backend.The text was updated successfully, but these errors were encountered: