I am trying to get multiple random documents from a dynamic collection. Until know, I have thought to do it using simple queries, something like this:
Pseudocode
arr = [];
while (arr.length < 5) {
// Start the query at a random position
startAt = Math.random() * collection.size;
randomDoc = await dbRef.startAt(startAt).limit(1).get( ... );
arr.push(randomDoc);
}
Here, firstly, I have to get the collection size, as it can be 0 or bigger. Then, select a random document using a kind of "db random pointer/index".
My question is if there is any way to get the same result but without all the loop stuff, only with the query syntax.
Thank you.