简体   繁体   English

如何将嵌套数组值推送到mongodb文档?

[英]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.

相关问题 如何使用Mongoose将值推入MongoDB中嵌入式文档中的数组? - How do I $push a value to an array within an embedded document in MongoDB using Mongoose? 如何将文档推送到嵌套在另一个数组中的数组中? - How to push a document in an array nested in another array? 如何从 object 获取嵌套值并推送到 MongoDB 中另一个新创建的对象/文档? - How to get nested values from an object and push to another newly created object/document in MongoDB? 如何使用mongodb将字典推送到嵌套数组? - how to push a dictionary to a nested array with mongodb? 如何使用 Mongoose 将数据推送到 MongoDB 中的嵌套数组 - How to push data with Mongoose to a nested array in MongoDB 如何使用JavaScript push()将一组值推入数组? - How do I push a group of values to an array with Javascript push()? 如何在 mongodb 文档中设置累积值? - How do I set cumulative values in a mongodb document? 如何将元素推入JavaScript中的嵌套数组中? - How do I push elements into a nested array in javascript? 如何将参数推入多个嵌套的数组/对象结构中? - How do I push a parameter into a multiple nested array/object structure? 如何在 mongodb 中设置对象嵌套数组的值 - How to set values of nested array of objects in mongodb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM