添加主引擎的数据库更新功能(之前只有插入和查询)

This commit is contained in:
chenxy123 2016-11-22 21:39:41 +08:00
parent bef9248e7e
commit 9e0d28c12a

View File

@ -233,7 +233,7 @@ class MainEngine(object):
try:
# 设置MongoDB操作的超时时间为0.5秒
self.dbClient = MongoClient(host, port, serverSelectionTimeoutMS=500)
self.dbClient = MongoClient(host, port, connectTimeoutMS=500)
# 调用server_info查询服务器状态防止服务器异常并未连接成功
self.dbClient.server_info()
@ -248,7 +248,7 @@ class MainEngine(object):
if self.dbClient:
db = self.dbClient[dbName]
collection = db[collectionName]
collection.insert(d)
collection.insert_one(d)
#----------------------------------------------------------------------
def dbQuery(self, dbName, collectionName, d):
@ -260,6 +260,14 @@ class MainEngine(object):
return cursor
else:
return None
#----------------------------------------------------------------------
def dbUpdate(self, dbName, collectionName, d, flt, upsert=False):
"""向MongoDB中更新数据d是具体数据flt是过滤条件upsert代表若无是否要插入"""
if self.dbClient:
db = self.dbClient[dbName]
collection = db[collectionName]
collection.replace_one(flt, d, upsert)
#----------------------------------------------------------------------
def getContract(self, vtSymbol):