0

I am confused on finding a way to convert this mongo shell query to Laravel (using jenssegers).

Here is the collection I have: test

{
    "_id" : ObjectId("5d84b2b27ef856d9e55eef67"),
    "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"
                }
            ]
        }
    ]
}

and my update query is:

db.getCollection('test').update(
    { _id : ObjectId("5d84b2b27ef856d9e55eef67") }, 
    { $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" } ] } )

How can I convert this query, so that I can run it from Laraval jenseggers.

VishnuPrasad
  • 1,078
  • 5
  • 17
  • 36
  • What have you tried? Conversion to PHP is generally just a matter of replacing `{}` with `[]` and `:` in between the key/values to `=>` – Neil Lunn Sep 23 '19 at 11:19
  • is it that simple...!!! could you please share the answer? @NeilLunn – VishnuPrasad Sep 23 '19 at 11:37
  • Done. Also an example of PHP syntax conversion [arrayFilters on mongodb php update](https://stackoverflow.com/q/55454528/2313887). Also [Is “How do I convert code from this language to this language” too broad?](https://meta.stackoverflow.com/q/296119/2313887) – Neil Lunn Sep 23 '19 at 11:41

0 Answers0