+ 1
How to get a random doc from a collection in firebase (JavaScript)?
For this task I’ll need to first receive the length of the collection, generate a random number with the collection length, and then grab a random document from the collection. How can this be achieved using JavaScript?
1 Respuesta
0
firebase storage has a listAll()
Documentation:
https://firebase.google.com/docs/storage/web/list-files
Reference:
https://firebase.google.com/docs/reference/node/firebase.storage.Reference#listall
Example:
https://gist.github.com/sawaYch/f538d10d09ccf84cbff07e93a0b6cd0d
You can then pick a random element of the items array in the ListResult.
These items are item references, so you can directly call their .getMetadata() or .getDownloadURL() (depending on what you want to do)