Spaces:
Sleeping
Sleeping
| import asyncio | |
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from app.config import settings | |
| async def rename_field(): | |
| client = AsyncIOMotorClient(settings.mongo_uri) | |
| db = client[settings.mongo_db_name] | |
| chat_logs = db["ChatLogs"] | |
| result = await chat_logs.update_many( | |
| {"chatbot": {"$exists": True}}, # filter documents where "chatbot" exists | |
| {"$rename": {"chatbot": "chatbot_id"}} # rename field | |
| ) | |
| print(f"Matched {result.matched_count}, Modified {result.modified_count} documents.") | |
| if __name__ == "__main__": | |
| asyncio.run(rename_field()) | |