我将尝试使用动态键推送数据
数据库结构:
{
"obj1":{
"array":[
{
"field1":"text1"
},
{
"field2":"text2"
}
]
},
"id":123;
},
{
"obj2":{
"array":[
{
"field1":"text1"
},
{
"field2":"text2"
}
]
},
"id":1234;
}
我正在尝试将变量用作映射路径中的键:
var a = 'obj2';
db.collection('fooCollection').update({'id':1234},{$push:{a.array:{ "field3":"text3"}}});
如果我这样做:
db.collection('fooCollection').update({'id':1234},{$push:{"obj2.array":{ "field3":"text3"}}});
这个功能可以正常工作,但我非常需要使用动态密钥。
"
和一个:
,但我不确定)。 - Aaron Dufour