mongo批量操作存在更新否则插入
def save_data(ok_ps):
ns = []
for ok in ok_ps:
ok['last_use_time'] = 0
ok['protocol'] = 0 # 协议类型 0:http
ok['is_own'] = 1
ok['is_ok'] = 0 # 可用
ok['date'] = datetime.datetime.utcnow()
ns.append(ReplaceOne({'ip': ok['ip']}, ok, upsert=True))
if len(ns) > 0:
res = coll.bulk_write(ns)