loopback update所有功能问题

loopback updateAll function problems

我有一个名为 Item 的模型,我想增加 Item 的数量

所以我编码:

Item.updateAll({name:'bar'},{count:'count'+1},function(err,items){

});

可惜没用

我知道我可以做到

Item.findOne({name:'bar'},function(err,item){
    Item.updateAll({name:'bar'},{count:item.count+1},function(err,items){

    })
});

但它就像一个傻瓜。

有什么增加计数的漂亮方法吗?

此答案仅适用于 mongodb 连接器 AFAIK,因为它使用 $inc 运算符。您需要将 "allowExtendedOperators": true 添加到您的数据源,请参阅 this issue 了解更多信息。

这会将 count 属性更新 1

Item.updateAll({name:'bar'}, {'$inc': {count: 1}}, function(err, items) {
  console.log('updated', items);
});