motor 提供了delete_many 方法用于批量删除mongo数据,它接收查询条件,所有符合查询条件的数据都会被删除
import pprint
import asyncio
import motor.motor_asyncio
uri = "mongodb://kwsy:123456@localhost:27017/app"
client = motor.motor_asyncio.AsyncIOMotorClient(uri)
db = client.app
user = db.user
async def do_delete():
result = await user.delete_many({'name': '小红'})
print(result.deleted_count)
loop = asyncio.get_event_loop()
loop.run_until_complete(do_delete())
QQ交流群: 211426309