ManTea commited on
Commit
9121797
·
1 Parent(s): 27b4122

fix connect mongodb

Browse files
Files changed (1) hide show
  1. 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(15))
 
 
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 ""