推送json数组MongoDB中的数据

时间:2015-10-19 06:24:27

标签: json mongodb push

我的mondoDB中有以下结构:

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

我想在源数组中添加另一个json用于以下resut:

    "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会对它进行什么查询?

1 个答案:

答案 0 :(得分:1)

了解$ push here


您的代码将是这样的

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