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):