AngularFire2 Firestore has a method called createId()
which auto-generates an id locally.
I was planning to use this with a form that handles a picture besides text.
To make things easier for the user, once he or she uploads a picture, I'll generate an Id that will be used as a ref for firebase storage. (So it has a relationship with the info going to the database)
I think this helps because the uploading process happens before the user submits the form, much like how gmail does things. You attach a file, and while it uploads, the submit button is disabled. Only when the percentage is 100 then the button is enabled the user can submit the said information to cloud firestore.
Now my problem is that, what if it generates an existing id? Wouldn't it replace the old data?(The items in that node will have a fairly big amount of documents)
How then can I avoid this?
Thanks for reading! Any tips are welcome :)
The random id generation for Firestore documents has a tremendous amount of entropy. The chance of a collision with a prior generated random is astronomically small. If that isn't good enough, you can generate your own unique IDs with even more randomness with some other library that generates even more entropy on unique IDs, such as as UUID. But I suspect that you'll be just fine with whatever Firestore generates for you.