【发布时间】:2016-02-24 22:11:22
【问题描述】:
我正在尝试使用以下代码将值推送到数组的特定索引处的数组:
Freezer.update(conditions, {$push: {shelves[shelfindex] : {"rackname": rackname, "columns": columns, "rows": rows, "spaces" : []}}}, function (err, doc){
console.log(doc);
})
其中shelfindex 是手头架子的索引,我发现它带有前面的for 循环(代码未显示)。
它不工作(程序甚至无法启动)。我收到以下错误:
SyntaxError: Unexpected token [
我的架子数组设置如下:
[{"racks":[],"shelfname":"Shelf 1"},{"racks":[],"shelfname":"Shelf 2"},{"racks":[],"shelfname":"Shelf 3"}]
例如,如果我试图将机架数据推送到“货架 1”,我会尝试将其推送到:
shelves[0].racks
有解决方案的想法吗?
【问题讨论】:
标签: arrays node.js mongodb mongoose