#How to query random three data ?
18 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
Well
You can query all your docs
Then you could do something like
// Array
const array = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
const shuffled = array.sort(() => 0.5 - Math.random());
const selected = shuffled.slice(0, 3);
console.log(selected)
So this shuffles an array randomly and picks the first 3 items
Once you get all your documents from a query, you could filter them using this logic
@main bane does that help?
not really. because i don't want to fetch all the data. just random three. anyway maybe i'll have to think about another approach. thanks 🙏
To not get every document, you can get the total doc count via the local API
Then get 3 unique random numbers from that number range
and query those 3 documents separately
Okay thanks