akn-dev / test.py
randydev's picture
fix update
1134589
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
client_tiktok = AsyncIOMotorClient("mongodb://localhost:27017/")
db_tiktok = client_tiktok["Akeno"]
collection = db_tiktok["session"]
async def get_session_all():
session = await collection.find().to_list(length=None)
print(session)
async def delete_session_all():
ok = await collection.delete_many({})
print("All sessions deleted.", ok.deleted_count)
async def approve_session_all():
session = await collection.find().to_list(length=None)
for i in session:
for client in i["user_client"]:
if client["status"] == "approved":
await collection.update_one(
{
"_id": i["_id"],
"user_client": {
"$elemMatch": {
"status": "approved"
}
}
},
{
"$set": {
"user_client.$.status": "approved",
"user_client.$.is_active": True,
}
}
)
asyncio.run(delete_session_all())