Laravel-Jenssegers MongoDB嵌套数组更新不起作用 [英] Laravel - Jenssegers MongoDB nested array update not working

查看:343
本文介绍了Laravel-Jenssegers MongoDB嵌套数组更新不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指出我的代码有什么问题吗? 我正在尝试通过Laravel Jenssegers更新MongoDB中的嵌套数组.这是我的代码

can someone please point out what wrong with my code? I am trying to update a nested array in MongoDB via Laravel Jenssegers. Here is my code

 $update_status = Journal::where('_id', "5cd10b325586e9122761f675" )
    ->update(
        [], 
        [ '$set' =>
            [
                "workflow.$[i].stages.$[j].stage_code" => "edit",
                "workflow.$[i].stages.$[j].stage_name" => "Editing"
            ]
        ],
        [ 'arrayFilters' => [
                [ "i.basic_details.wfCode" => 'wf1' ],
                [ "j.stage_id" => "wf1_2" ]
            ]
        ]
    );

和我的Journal集合是:

{
    "_id" : ObjectId("5cd10b325586e9122761f675"),
    "workflow" : [ 
        {
            "basic_details" : {
                "wfCode" : "wf1"
            },
            "stages" : [ 
                {
                    "stage_id" : "wf1_1",
                    "stage_code" : "submission",
                    "stage_name" : "Submission",
                    "button_label" : "submit"
                }, 
                {
                    "stage_id" : "wf1_2",
                    "stage_code" : "s2",
                    "stage_name" : "S2",
                    "button_label" : "label2"
                }
            ]
        }
    ]
}

执行后,我将$update_status设置为1,但是在查看集合时,它保持不变.

After execution, I am getting $update_status as 1, but while looking into the collection, it remains unchanged.

推荐答案

请检查此查询,我认为这应该有效...

Please check this query, i think this should work...

$articleId = new ObjectID("5cd10b325586e9122761f675");
$result = Journal::raw(function ($collection) use ($articleId) {
return $collection->updateOne(
    array ('_id' => $articleId), 
    array ('$set' => 
        array(
            'jnl_workflow.$[i].wf_stages.$[j].wf_stage_code' => "edit",
            'jnl_workflow.$[i].wf_stages.$[j].wf_stage_name' => "Editing" 
        )
    ), 
    array( 'arrayFilters' => [ array ('i.wf_basic_details.wfCode' => 'wf1'), array('j.wf_stage_id' => "wf1_2" ) ] ) 
)

});

这篇关于Laravel-Jenssegers MongoDB嵌套数组更新不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆