Query Random Data from a collection

How can I query random data from a collection using the Moralis query?
I have tried something like this

const Gardens = Moralis.Object.extend("Gardens")
    const query = new Moralis.Query(Gardens)
    query.aggregate([{ $sample: { size: 1 } }])
 const result = await query.find()

but it doesn’t seem to work

it looks like you could simulate a random value with skip parameter

https://community.parseplatform.org/t/query-with-a-random-result/2217
1 Like

I will try it out and see. But that means I would have to get the number of items in the collection first,

You can do that with a count

1 Like