Spaces:
Sleeping
Sleeping
fix connect mongodb
Browse files- mongodb.py +3 -1
mongodb.py
CHANGED
@@ -39,7 +39,9 @@ def get_chat_history(user_id: int) -> str:
|
|
39 |
try:
|
40 |
# Truy vấn tất cả các document có user_id, sắp xếp theo timestamp tăng dần
|
41 |
# Nếu không có trường timestamp, có thể sort theo _id
|
42 |
-
docs = list(collection.find({"user_id": user_id}).sort("timestamp", 1).limit(
|
|
|
|
|
43 |
if not docs:
|
44 |
logger.info(f"Không tìm thấy dữ liệu cho user_id: {user_id}")
|
45 |
return ""
|
|
|
39 |
try:
|
40 |
# Truy vấn tất cả các document có user_id, sắp xếp theo timestamp tăng dần
|
41 |
# Nếu không có trường timestamp, có thể sort theo _id
|
42 |
+
docs = list(collection.find({"user_id": user_id}).sort("timestamp", -1).limit(20))
|
43 |
+
docs.reverse()
|
44 |
+
|
45 |
if not docs:
|
46 |
logger.info(f"Không tìm thấy dữ liệu cho user_id: {user_id}")
|
47 |
return ""
|