[英]How do I push nested array values to a mongodb document?
If I have a document in mongodb with this structure: 如果我在mongodb中有一个具有以下结构的文档:
{
"_id": "user1",
"loc": [
{
"lon": 51.12076493195686,
"lat": -113.98040771484375
},
{
"lon": 51.10682735591432,
"lat": -114.11773681640625
}
]
}
How would I be able to push a new array containing lon and lat within the loc list? 我怎样才能在loc列表中推送包含lon和lat的新数组?
The structure I am trying to use is this: db.collection('location').update({_id:'user1'},{'$push': {"lat": "-107.10400390625", "lon": "33.32343323432" }})
我试图使用的结构如下: db.collection('location').update({_id:'user1'},{'$push': {"lat": "-107.10400390625", "lon": "33.32343323432" }})
This obviously does not work because the lat and lon are nested within loc. 这显然不起作用,因为lat和lon嵌套在loc中。
db.collection('location').update({_id:'user1'},{'$push': { "loc": {"lat": "-107.10400390625", "lon": "33.32343323432" }}})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.