import pymssql
from pymongo import MongoClient
conn = pymssql.connect(‘IP‘, ‘用户名‘, ‘密码‘, ‘数据库‘)
cursor = conn.cursor(as_dict = True)
cursor.execute(" select top 1000 V_ALERTS.SOURCE,V_ALERTS.FILEPATH,V_ALERTS.ALERTDATETIME,V_ALERTS.ALERTENDDATETIME,ALERTMSG.ALERT ,SEM_COMPUTER.COMPUTER_NAME,SEM_COMPUTER.CURRENT_LOGIN_USER from (V_ALERTS left join ALERTMSG on V_ALERTS.ALERT_IDX= ALERTMSG.ALERT_IDX) left join SEM_COMPUTER on V_ALERTS.COMPUTER_IDX = SEM_COMPUTER.COMPUTER_ID")
client = MongoClient(‘localhost‘, 27017)
db = client.SEPM
collection = db.sepm
for row in cursor:
print(row)
collection.insert_one(row)
for item in collection.find():
print(item)
原文地址:http://blog.51cto.com/unicom/2124802
时间: 2024-10-03 15:14:09