Spaces:
Build error
Build error
| from pymongo import MongoClient | |
| # 替换成你自己的 MongoDB URL | |
| MONGODB_URL = "mongodb+srv://james20141606_db_user:[email protected]/?retryWrites=true&w=majority&appName=Cluster0" | |
| # 连接数据库 | |
| client = MongoClient(MONGODB_URL) | |
| # 创建或访问数据库(比如 chatdb) | |
| db = client["chatdb"] | |
| # 打印数据库中的集合(collection)列表 | |
| print("✅ 当前数据库中的集合:", db.list_collection_names()) | |
| # 尝试访问一个名为 conversations 的集合(假设 ChatUI 会把聊天写入这里) | |
| if "conversations" in db.list_collection_names(): | |
| print("\n最近 5 条聊天记录:") | |
| for chat in db.conversations.find().sort("_id", -1).limit(5): | |
| print(chat) | |
| else: | |
| print("\n⚠️ 尚未检测到 'conversations' 集合,请确认 ChatUI 已经写入过对话数据。") |