mongo_api.py 765 B

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2023/7/21 8:51
  3. # @Author : XuJiakai
  4. # @File : mongo_api
  5. # @Software: PyCharm
  6. import asyncio
  7. from data_clean.utils.async_client import get_aio_mongo_db
  8. db = get_aio_mongo_db()
  9. async def insert_one(collection, data):
  10. result = await db[collection].insert_one(data)
  11. return result.inserted_id
  12. pass
  13. async def insert_many(collection, data: list):
  14. result = await db[collection].insert_many(data, ordered=False)
  15. return result.inserted_id
  16. pass
  17. async def test():
  18. # res = await db["a_xjk_test_aio"].insert_one({"a": "b"})
  19. # print(res.inserted_id)
  20. res = await insert_one("a_xjk_test_aio", {"_id": "b", "c": "a"})
  21. print(res)
  22. pass
  23. if __name__ == '__main__':
  24. asyncio.run(test())
  25. pass