import xml.etree.ElementTree as ET from subdir import service from bson.objectid import ObjectId from pymongo import MongoClient import asyncio client = MongoClient() db = client["baojia"] collection = db["qdxm"] for post in collection.find(): if "__children" in post: child = post["__children"] for entry in child: if '附注' in entry['清单编码'] and '换' in entry['清单编码']: print(entry['清单编码'])