I have data in a table that I would like to sync to a Firestore collection (1 row -> 1 document), but the Ids are incrementing numbers, so I don't want to use the Id in the table as the document Id, due to hotspotting.
I'm thinking of hashing the Id and am looking for a hashing function that returns a firestore like id, (I believe the regex is ^[a-zA-Z0-9]{20}$
)
Any ideas or alternative strategies?
CodePudding user response:
Hashing is a good place to start, and likely your only option. Hashes could run into collisions (with a likelihood dependent on the algorithm you choose). You can work around that by suffixing the hash with the actual number in order to ensure they are absolutely unique. So, something like [hash]_[rownum]
.
You have no requirement to make the hash look like what Firestore generates because Firestore just generates random IDs in the client SDK (not on the server). You can use any ID utf-8 string format you like so long as the strings are unique.