MongoDB - PHP修改数组的对象值

时间:2016-08-16 10:03:57

标签: php arrays mongodb laravel-4

我有一个存储对象数组的字段。我想修改对象"状态"价值取决于" id"对象拥有的价值。

"authors" : [ 
        {
            "id" : "18",
            "first_name" : "Buddhika",
            "last_name" : "Chathuranga",
            "$$hashKey" : "object:35",
            "status" : NumberLong(0)
        }, 
        {
            "id" : "3", // search for this number
            "first_name" : "Pasindu",
            "last_name" : "Priyanath",
            "$$hashKey" : "object:43",
            "status" : NumberLong(0) // modify this to 1
        }
    ],

1 个答案:

答案 0 :(得分:0)

在Mongo DB php中更新:

db.collection.update( criteria, objNew, upsert, multi );

Detail Explanation