From 9e0d28c12a4983343aaeb726d3d4e6607f1ad8b5 Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Tue, 22 Nov 2016 21:39:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9B=B4=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=88=E4=B9=8B=E5=89=8D=E5=8F=AA=E6=9C=89=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E5=92=8C=E6=9F=A5=E8=AF=A2=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/vtEngine.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index 11b83270..c4a21248 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -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):