在 json 数组 MongoDB 中推送数据

Push data in json array MongoDB

我的 mondoDB 中有以下结构:

    "source" : [
            {
                    "source_id" : "800000021",
                    "source" : "Test1"
            }
    ]
    "state" : "AM",
    "owner_phone" : "0",
    "latitude" : 0,
    "leedon_activated" : "True",
    "zip_code" : "12345",
    "fax" : "0",

我想为以下结果添加另一个 json 到源数组:

    "source" : [
            {
                    "source_id" : "800000021",
                    "source" : "Test1"
            },
            {
                    "source_id" : "800000022",
                    "source" : "Test2"
            }
    ]
    "state" : "AM",
    "owner_phone" : "0",
    "latitude" : 0,
    "leedon_activated" : "True",
    "zip_code" : "12345",
    "fax" : "0"

会MongoDB查询什么?

了解 $push here


你的代码会像这样

yourmodelname.update({ /* some conditions to updating files */ },{$push: {"source": {"source_id" : "213123", "source" : "asdasd"}}})