添加主引擎的数据库更新功能(之前只有插入和查询)
This commit is contained in:
parent
bef9248e7e
commit
9e0d28c12a
@ -233,7 +233,7 @@ class MainEngine(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 设置MongoDB操作的超时时间为0.5秒
|
# 设置MongoDB操作的超时时间为0.5秒
|
||||||
self.dbClient = MongoClient(host, port, serverSelectionTimeoutMS=500)
|
self.dbClient = MongoClient(host, port, connectTimeoutMS=500)
|
||||||
|
|
||||||
# 调用server_info查询服务器状态,防止服务器异常并未连接成功
|
# 调用server_info查询服务器状态,防止服务器异常并未连接成功
|
||||||
self.dbClient.server_info()
|
self.dbClient.server_info()
|
||||||
@ -248,7 +248,7 @@ class MainEngine(object):
|
|||||||
if self.dbClient:
|
if self.dbClient:
|
||||||
db = self.dbClient[dbName]
|
db = self.dbClient[dbName]
|
||||||
collection = db[collectionName]
|
collection = db[collectionName]
|
||||||
collection.insert(d)
|
collection.insert_one(d)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def dbQuery(self, dbName, collectionName, d):
|
def dbQuery(self, dbName, collectionName, d):
|
||||||
@ -261,6 +261,14 @@ class MainEngine(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
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):
|
def getContract(self, vtSymbol):
|
||||||
"""查询合约"""
|
"""查询合约"""
|
||||||
|
Loading…
Reference in New Issue
Block a user