Loopback: Atomic read and update

送分小仙女□ 提交于 2019-12-10 23:08:41

问题


is there a way to implement something like this in loopback?

LOCK
 READ
 INCREMENT
UNLOCK

I would like to keep counters as database values, each key is a counter (or a setting), and they shouldn't accessed my multiple requests at the same time.

Also this should work for local requests too (no remoteHooks)

Thanks


回答1:


If you are using the mongoDB connector, this is supported by extended operators.

MyModel.updateAll(
  { id: 123' },
  { '$inc': { myproperty: 1 }}, // increment myproperty by 1
  { allowExtendedOperators: true }
);

Otherwise, you can use transactions as a workaround for some connectors.



来源:https://stackoverflow.com/questions/40108092/loopback-atomic-read-and-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!