码迷,mamicode.com
首页 > 数据库 > 详细

Python将SQL server 数据库导入到mongoDB数据库中

时间:2018-06-04 21:32:22      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:python

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)

Python将SQL server 数据库导入到mongoDB数据库中

标签:python

原文地址:http://blog.51cto.com/unicom/2124802

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!