Firestore generated unique ids for more then 1 col

2019-08-18 04:31发布

Within the project that I am currently working on a document need to be placed from one collection to the other one.

This is done by deleting a document from one collection and save it into another collection (using the same ID).

The problem I am facing is regarding the uniqueness of the generated ID.

Question1:

Can Firestore generate an ID that once already occurred in that collection even tho the document having that ID was removed?

Imagine the following collection:

collectionY[
 1: {},
 2: {}
 ...
]

We remove document with id 1 and save it in another collection. Will collectionY ever generate id 1 again for any new documents?

1条回答
我只想做你的唯一
2楼-- · 2019-08-18 05:19

Will collectionY ever generate id 1 again for any new documents?

The collisions of ids in this case is incredibly unlikely and you can/should assume they'll be completely unique. That's what they were designed for. So you don't have to be concerned about it.

This built-in generator for unique ids that is used in Firestore when you call CollectionReference's add() methods or CollectionReference's document() method without passing any parameters, generates random and highly unpredictable ids, which prevents hitting certain hotspots in the backend infrastructure.

查看更多
登录 后发表回答