D
D
Dmitry Sudarkin2017-09-16 19:31:12
MongoDB
Dmitry Sudarkin, 2017-09-16 19:31:12

Where is the error in the MongoDB query?

Hello. I make a request, it seems to be correct, but update () does not work correctly

$update['modules.$.elements.$.html']  = 'ТЕСТ';
        $result = Blocks::where([
            '_id' => $block_id,
            'modules' => [
                '$elemMatch' => [
                    'module_id' => $module_id,
                    'elements' => [
                        '$elemMatch' => [
                            'element_id' => $element_id
                        ]
                    ]
                ]
            ]
        ])->update($update);

Record finds, but does not want to update. If I update like this,
$update['modules.$.elements'] = 'ТЕСТ';
then everything is OK. But in the next nesting does not save. What's wrong with the request? How can the html parameter be saved?
Structure
"_id": "1",
    "modules" : [ 
        {
            "module_id" : "2",
            "elements" : [ 
                {
                    "element_id" : "3",
                    "html": "<div></div>"
                }
            ]
        }
    ]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question