我收到错误未捕获异常: TypeError: doc.addresses.append is not a function
我有这样的结构:
_id: ObjectId("3c4b1475238d3b4dd5000001"),
username: "kris",
addresses:
[
{
name: "home",
street: "123 Some Ave",
city: "Cul City",
state: "CA",
zip: 12345
},
{
name: "work",
street: "1234 Sea Blvd",
city: "Cul City",
state: "CA",
zip: 54321
}
]
我正在尝试这样做:
UID=ObjectId("3c4b1475238d3b4dd5000001")
doc=db.users.findOne({_id: UID})
new_address={name:'work', street:'17w. 18th St', city: 'New York', state:'NY', zip:10011}
doc['addresses'].append(new_address)
但我收到此错误: 未捕获的异常:TypeError:doc.addresses.append不是函数: 我该如何解决它?
I have a structure like this:
_id: ObjectId("3c4b1475238d3b4dd5000001"),
username: "kris",
addresses:
[
{
name: "home",
street: "123 Some Ave",
city: "Cul City",
state: "CA",
zip: 12345
},
{
name: "work",
street: "1234 Sea Blvd",
city: "Cul City",
state: "CA",
zip: 54321
}
]
I'm trying to do this:
UID=ObjectId("3c4b1475238d3b4dd5000001")
doc=db.users.findOne({_id: UID})
new_address={name:'work', street:'17w. 18th St', city: 'New York', state:'NY', zip:10011}
doc['addresses'].append(new_address)
But i get this error:
uncaught exception: TypeError: doc.addresses.append is not a function :
How can i solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
附加到数组的正确
javascript
方法是push
。因此,不要使用:
使用:
The proper
javascript
method to append to an array ispush
.So, instead of:
use: