get random

This commit is contained in:
Administrator
2022-10-05 18:00:15 +03:00
parent 501c1b2ccf
commit a166c0ef42
2 changed files with 3 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ def fetch_jokes():
def get_random() -> str:
count_docs = mongo.jokes_collection.count_documents({})
rnd = random.randrange(1, count_docs + 1)
anek = mongo.jokes_collection.aggregate([{"$sample": {"size": 1}}])[0]
anek = mongo.jokes_collection.aggregate([{"$sample": {"size": 1}}]).next()
return anek['text']