【发布时间】:2018-03-07 18:42:01
【问题描述】:
如何使用 MongoDB/Meteor 将数组添加到现有数组中?这是数据库的结构。
我想在 [depute] 内添加一个新数组,而不是像现在这样在外面添加一个新数组。
到目前为止,这是代码。
Meteor.methods({
'votes.insert': function (depute, loi, choix){
console.log('from votes.insert', depute, loi, choix)
return Deputies.update(depute,
{$push: {votes: {[loi]:choix}}}
);
},
});
它在 [depute] 旁边添加了一个新数组 [votes],而不是在 [depute] 内。
有什么提示吗?
【问题讨论】:
-
试试
Deputies.update(depute, {$push: {'depute.votes': {[loi]:choix}}} );depute 看起来不像是一个数组,它是一个嵌入文档。 -
这里是json文件的结构 { "deputes" : [ { "depute" : { "adresses" : [ { "adresse" : "这是地址" } ], "anciens_mandats" : [ {
-
插入投票数组的搜索条件是什么?您需要将投票推入哪个代理数组元素?