I need to create a document inside a transaction.
The transaction object doesn't have the add function, probably because it would create multiple documents in case the Firestore
retry the transaction.
The only way i can think is to use GUID
as document id, but they make very long indexes to lookup.
Is there any way around? Another approach?
I wouldn't be too concerned about the length of a document ID. I don't think you'll find that performance will suffer if you use a GUID for an ID. If you're concerned about size, only you can compute about how much of your storage is consumed by IDs.
If you want to limit the size of a random document ID, you can simply generate your own random data and convert that to a string that follows the rules for Firestore document IDs. It could be something as simple as generating a X number of random letters and concatenating them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With