I have a Firestore collection called users
that stores all my user info. When registering a new user, I first register them with Firebase Auth, then create the record in the users
collection. Right now I'm storing the UID
as a field, which means when I want to query a user's info, I need to do a query with a WHERE
clause. However, one alternative to faster querying would be to store the UID
as the document ID for the collection. That would make it so that I could query the collection with a specific ID, which intuitively seems faster.
Using the UID
as the doc ID makes me worried about some stuff:
- I'm not sure if I can assume that uniqueness for the
UID
in Firebase Auth implies uniqueness when using it as the doc ID in a Firestore collection. - I watched a tutorial video by Todd that said that querying is faster if you use the auto-generated document ID that Firestore provides. Given this, I wouldn't want to take a risk using something else when the provided doc ID is known to be faster for querying.
What would be the better approach to make querying as efficient as possible, assuming you are querying only based on UID
? Or is the difference so negligible that this is a moot point?