#community-help

Retrieving Random Documents from a Collection

TLDR Alexander asked for ways to retrieve random documents from a collection. Jason advised using a random integer field in all records, and filtering using a random numeric range to get the documents.

Powered by Struct AI

1

Apr 06, 2022 (21 months ago)
Alexander
Photo of md5-8ac455f6d302407f03def4c775778b28
Alexander
04:53 PM
Is there a way to get x random documents from a collection? I can only think of unsexy solutions
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:56 PM
Hey Alexander! There's no direct way to do this...
Alexander
Photo of md5-8ac455f6d302407f03def4c775778b28
Alexander
04:57 PM
ok 😄 I saw tht in the docs, I am trying to find a work around
04:58
Alexander
04:58 PM
Tanks for the reply Jason
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:00 PM
I guess one way would be to have a random integer field in every record, then filter by a random numeric range on that field and take the first 10 docs?
Alexander
Photo of md5-8ac455f6d302407f03def4c775778b28
Alexander
05:03 PM
yea that's what I was thinking too
05:03
Alexander
05:03 PM
this is my work around for now :)
05:14
Alexander
05:14 PM
Copilot says you are wrong 😆

1