我正在尝试在 mongodb 上执行更新,使用 motor 和 tornadoweb 以及以下代码:
@gen.coroutine
def set_project_status(self, pid, status):
try:
project = yield motor.Op(self.db[S.DB_PROJECT_TABLE].find_one, {'PID': pid})
logging.debug('set_project_status old_id {0}'.format(project['_id']))
project_update = yield motor.Op(self.db[S.DB_PROJECT_TABLE].update,
{'_id': ObjectId(project['_id'])}, {'STATUS': status})
logging.debug('set_project_status saving')
save = yield motor.Op(self.db[S.DB_PROJECT_TABLE].save, project_update)
logging.debug('set_project_status saved {0}'.format(save))
logging.debug('set_project_status saved id {0}'.format(project_update))
project = yield motor.Op(self.db[S.DB_PROJECT_TABLE].find_one, {'PID': pid})
logging.debug('set_project_status project {0}'.format(project))
raise gen.Return(True)
except Exception,e:
logging.debug('{0} {1} {2}'.format(pid, status, e))
raise gen.Return(False)
我在日志中得到的是:
set_project_status old_id 52d532d4b12c6478ce767a83
set_project_status saving
set_project_status saved 52d532d4b12c6478ce767a84
set_project_status saved id {u'ok': 1.0, u'err': None, u'connectionId': 2052, u'n': 1, u'updatedExisting': True, '_id': ObjectId('52d532d4b12c6478ce767a84')}
set_project_status project None
我得到了一些中间对象(u'updatedExisting ?),稍后没有。
我似乎,就像我应该做一些'提交'左右。有任何想法吗?
问候!