-
Hi all, I have a LARGE Base and was wondering what the best way to get one single record, at random, would be. Something similar to MongoDB's aggregation:
Or something similar to pymongo's count = collection.count_documents( {} ) # using an empty filter
item = collection.find_one( {} , skip=count) I have thought of two ways to do this, which would be the best route, or is there another way that would be more performant? My thoughts were:
res = db.fetch()
all_items = res.items
while res.last:
res = db.fetch(last=res.last)
all_items += res.items
import random
desired_item = random.choice(all_items) However this is going to be very time consuming and inefficient due to my base's size.
If anyone has suggestions or better ideas please let me know, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
First I want to know what type of keys you are using to store the records? |
Beta Was this translation helpful? Give feedback.
-
deta base doesn't support this capability. the randomization should happen outside the query. in addition to what @jnsougata suggested, it might also be possible to generate a specific time in the past and use comparison operators to get a random result. not sure how well this would work in reality. |
Beta Was this translation helpful? Give feedback.
deta base doesn't support this capability. the randomization should happen outside the query. in addition to what @jnsougata suggested, it might also be possible to generate a specific time in the past and use comparison operators to get a random result. not sure how well this would work in reality.