Mongodb数据库删除数据为0的数据信息

时间:2022-01-23 22:18:15
from pymongo import MongoClient

def clink_DB():
    client = MongoClient('localhost', 27017)  # 链接数据库
    db = client['Taoguba']
    db.Taoguba.remove({"Content": ''})
    db.Taoguba.remove({"Talk": '0'})
    db.Taoguba.remove({"Skim": '0'})
    c = db.Taoguba.find()
    for i in c:
        skim = int(i["Skim"])
        talk = int(i["Talk"])
        num = (talk / skim)*100
        print(num)

def main():
    clink_DB()

if __name__ == '__main__':
    main()