0

Does anyone know how to create a Firestore Document with a specific, non-autogenerated ID? I would like the operation to fail if the document already exists, and I would like this to be a single operation (not one involving two reads)


Looking for Javascript solutions. Preferably with the web modular API (v9). I'm not sure how to find the source code for addDoc, so I don't know how to mimic the addDoc process with my own ID.


setDoc is not a solution to this problem, unless there is a way to make it fail if the document already exists. The default behaviour of setDoc is to either merge or replace existing documents, not "fail if exists".

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
touch my body
  • 1,634
  • 22
  • 36

0 Answers0