123456789101112131415161718192021222324252627282930313233343536373839404142 |
- # -*- coding: utf-8 -*-
- # @Time : 2023/7/21 8:51
- # @Author : XuJiakai
- # @File : mongo_api
- # @Software: PyCharm
- import asyncio
- from data_clean.utils.async_client import get_aio_mongo_db
- db = get_aio_mongo_db()
- async def insert_one(collection, data):
- result = await db[collection].insert_one(data)
- return result.inserted_id
- pass
- async def insert_many(collection, data: list):
- result = await db[collection].insert_many(data, ordered=False)
- return result.inserted_id
- pass
- async def delete_one(collection, object_id):
- result = await db[collection].delete_one({"_id": object_id})
- return result.deleted_count
- pass
- async def test():
- # res = await db["a_xjk_test_aio"].insert_one({"a": "b"})
- # print(res.inserted_id)
- res = await insert_one("a_xjk_test_aio", {"_id": "b", "c": "a"})
- print(res)
- pass
- if __name__ == '__main__':
- asyncio.run(test())
- pass
|