将参数传递给数组更新器方法{$ set:{"parameters":data}} [英] Passing parameters to the array updater method {$set: {"parameters": data}}

查看:78
本文介绍了将参数传递给数组更新器方法{$ set:{"parameters":data}}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Comanda.findOneAndUpdate(id,{$set: {"orden.0.fondos.2.estadoitem": estado}}, {}, function(err, comanda)

我需要间接更改

$set: {"orden.0.fondos.2.estadoitem" 

无论我做什么,我都无法..这将节省我的生活=/..

no matter what I do, i cant.. this will save my live =/..

我已经尝试了一切,调用var pos = 2;然后$ set:{"orden.0.fondos.pos.estadoitem"也作为字符串pos ="2";似乎没有任何作用

i have tried everything, calling a var pos = 2; and then $set: {"orden.0.fondos.pos.estadoitem" also as a string pos= "2"; and nothing seems to work

感谢撤离

推荐答案

您可以动态创建$set字段:

var set = { "$set": {} };
set.$set["orden.0.fondos." + pos + ".estadoitem"] = estado;

Comanda.findOneAndUpdate(id, set, {}, function(err, comanda) {

})

这篇关于将参数传递给数组更新器方法{$ set:{"parameters":data}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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