Skip to content
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

FR: Expose "create" precondition for firestore writes #1324

Open
ribrdb opened this issue Oct 22, 2018 · 2 comments
Open

FR: Expose "create" precondition for firestore writes #1324

ribrdb opened this issue Oct 22, 2018 · 2 comments

Comments

@ribrdb
Copy link

ribrdb commented Oct 22, 2018

It should be possibly to do a write that fails if the document already exists, like is possible in the admin sdk.
Instead I have to do something like:

  1. Read the document
  2. If it doesn't exist, read it again in a transaction
  3. If it exists now do a dummy update so the transaction can succeed, otherwise create it.
@mikelehen
Copy link
Contributor

Using a transaction is the recommended approach for this scenario... Or you can configure your security rules to make sure the write fails if the document already exists (though it'll be a permission_denied error in this case).

@thebrianchen
Copy link

With #2436, you will no longer have to perform a dummy update if your document exists, since we no longer require that every document read must be written to. Adding transaction.create() is still something that's on our radar, but it's relatively low-priority because this functionality can be achieved using the existing API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants