import pymysql
import pymongo
# 创建mysql的数据库连接
con = pymysql.connect(host='', port='', user='', password='', db='')
# 获取游标
cur = con.cursor(cursor=pymysql.cursors.DictCursor)
# 查询student表
result =[]
try:
cur.execute('select * from disease')
client = pymongo.MongoClient(host='', port='')
db = client['disease_knowledge']
for row in cur.fetchall():
if row['jbmc'] not in result:
print(row)
db.knowledge.insert_one(row)
result.append(row['jbmc'])
except Exception as e:
print(e)
finally:
con.close()
client.close()