from pymongo import MongoClient

class Save(object):
    def __init__(self, host):
        self.client = MongoClient(host=host, port=27017)
        # 使用的mongo的数据表
        self.db = self.client.ImageSet

    def _save_data_mongodb(self, collect_name, data):
        # 定义一个去重的图标集名称
        self.collect_name = self.db[collect_name]
        history_record = self.collect_name.find_one({"_id": data['title_id']})
        if history_record:
            # 数据库中已经存在数据
            return False
        else:
            # 数据库中不存在,插入数据 
            self.collect_name.update_one({'_id': data['title_id']}, {'$set': data}, upsert=True)
            return True

  

相关文章:

  • 2021-10-13
  • 2021-12-31
  • 2021-12-02
  • 2022-01-23
  • 2021-09-13
  • 2021-10-24
猜你喜欢
  • 2021-08-17
  • 2021-09-01
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2021-04-25
相关资源
相似解决方案