I am trying to query random user documents from Firebase Firestore.
I use the Firebase Auth UID as id's in Firestore, so instead of a 20-character UID my id's for the user's are the 28-character UID's from Auth.
To get a random document, I want to do the following:
const randomId = firestore.collection.doc().id
// ... all the query logic
.where(firebase.firestore.FieldPath.documentId(),'>',randomId)
I repeat this process if nothing is found. (like mentioned here).
This would work all great if I had a randomly generated Firebase ID, however since I have Firebase Auth ID's (which are longer), that process does not really work and some documents are never showed.
So I thought I could automatically generate a Firebase Auth UID, but that does not seem to work.
Something like this would be handy:
const randomId = firebase.auth().generateRandomUid()
So my questions:
- Is there a way to automatically generate a Firebase Auth UID without actually creating a user?
- Is there a better way to query random documents from Firestore with UID as id?
Changing ID's is not an option, and I would like to avoid generating a separate field for that.