0

In a Flutter application, I'm using the following code frequently to generate a document ID before writing the document to Firestore (to include the document ID inside the document):

docID = FirebaseFirestore.instance.collection(path).doc().id

Will this incur a read charge every time I do it?

osaxma
  • 2,657
  • 2
  • 12
  • 21

1 Answers1

2

No, it wont incur a read charge. You will only be charged for the write, because you are not actually reading anything off Firestore, the ID is generated client-side.

ThienLD
  • 741
  • 4
  • 14
  • Out of curiosity, how does Firestore ensure that the generated ID is unique to that collection if it's generated in the client-side? – osaxma Aug 31 '20 at 09:25
  • 1
    you can actually read the source code of how they do that, the question is asked here https://stackoverflow.com/questions/46618719/firestore-are-ids-unique-in-the-collection-or-globally .tl;dr : it's just based on math.random(), so it's not guaranteed to be unique – ThienLD Aug 31 '20 at 09:34
  • 2
    Such IDs are statistically guaranteed to be unique, which is a fancy way of saying that it's so random that the chances of two calls generating the same ID are infinitely small. – Frank van Puffelen Aug 31 '20 at 15:24