'Firebase Firestore stopped accepting ID's (non Auto-ID)
My firebase firestore DB has a sub-collection called "blockouts" where each document has an ID with 5 numbers and two trailing zeros. The zeros are important defaults. I could add documents with this ID pattern until yesterday. Now it automatically deletes the document immediately upon adding it. This happens when I manually try to add the document on the Firebase console.
As an example I cannot add document 1234500 or abcde00. But I can add 1234560 or abcdef0.
I think the problem is unique to this project because I tried using the pattern on the console in another project without a problem. But I need it to work in this project. Can anyone think of a reason this might be happening?

Solution 1:[1]
My first attempt at fixing this was to use 7 digits with two trailing 9s instead of trailing 0s. Firestore would then let me add a document like 1234599 on the console. So I changed my code to use trailing 9s instead of 0s. Then I ran my user initiation routine that uploads around 40 small documents in a for loop with this naming pattern. The documents would appear and then were quickly turned red and then deleted right in front of my eyes in the console. After that I could no longer add a document on the console following the pattern with trailing 9s. They would turn red and be deleted again. No errors appeared in my code catch block.
The red color had me thinking Satan was somehow involved in this.
But before bringing in an exorcist, I stumbled on "Best practices for Cloud Firestore". Here I found what I think are the problems.
Do not use monotonically increasing document IDs such as: Customer1, Customer2, Customer3, ... Product 1, Product 2, Product 3, ... Such sequential IDs can lead to hotspots that impact latency.
My pattern is similar to this, not sequential but continually increasing.
Also:
Avoid writing to a document more than once per second.
That was definitely happening for me. The 40 documents uploaded in about 1 sec.
So I tried putting a 1.5 second delay in my for loop. Now it seems to be uploading correctly even when I switched back to trailing zeros. The delay time is not a problem for me at this point. But I will look into the batch transactions option when I have the brain power.
I would recommend anyone considering using Firestore to review the Best Practices before committing. There could be some deal-breakers for you in there. And it may not be obvious that you broke one of the practices. My MO is to read docs only when something breaks and I get error messages. In this case no errors, just Satan.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PersistentJohn |
