Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a document inside a transaction

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?

like image 910
MiguelSlv Avatar asked Nov 08 '22 11:11

MiguelSlv


1 Answers

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.

like image 173
Doug Stevenson Avatar answered Nov 15 '22 08:11

Doug Stevenson