try: conn = MongoClient(cf.get('letschatcfg', 'mongodb_ip'), 27017) wxrooms_set = conn.letschat.rooms for i in wxrooms_set.find(): print(str(i['_id'])) if wxrooms_set.find_one() is None: print('not data') # 查看是否存在包含test命名的群 for i in wxrooms_set.find({'slug': {'$regex': '.*test.*'}}): # print(i['letschatroomname']) print(i['name']) result = wxrooms_set.delete_many({'slug': {'$regex': '.*.*'}}) print(result.deleted_count) except Exception as e: print(str(e))
pymongo查看集合数据是否为空,以及正则表达式
最新推荐文章于 2023-11-22 00:56:37 发布