环回:原子读取和更新 [英] Loopback: Atomic read and update

查看:101
本文介绍了环回:原子读取和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在环回中实现类似的东西?

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.

这也应该适用于本地请求(没有remoteHooks)

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

谢谢

推荐答案

如果您使用的是mongoDB连接器,则

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.

这篇关于环回:原子读取和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆