0

我一直在寻找有关在 mongoDB 中更新嵌套数组的信息。到目前为止,我知道深度数组上的位置 $ 运算符存在问题,请参见:https ://jira.mongodb.org/browse/SERVER-831

但是这里有没有人可以帮助我为此创建一个解决方法?这是我的示例架构:

{
    folder_data : [
        {
            "folderName" : "First",
            "otherFolder" : []
        },
        {
            "folderName" : "Second",
            "otherFolder" : [
                {
                    "folderName" : "SecondA",
                    "otherFolder" : [
                        {
                            "folderName" : "SecondB",
                            "otherFolder" : [

                                // put my new data here                             

                            ]
                        },
                        {
                            "folderName" : "SecondBextra",
                            "otherFolder" : []
                        }
                    ]
                },
                {
                    "folderName" : "SecondAextra",
                    "otherFolder" : []
                },
            ]
        }
    ]   
}

到目前为止,我已经完成了:

工作(对于第一个数组):

$collection->update(
            array('folder_data.folderName' => 'Second'), 
            array('$set' => array('folder_data.$.otherFolder' => array('test' => 'sample')))
        );

不工作:

$collection->update(
            array(
                'folder_data.folderName' => 'Second',
                'folder_data.otherFolder.folderName' => 'SecondA',
                'folder_data.otherFolder.otherFolder.folderName' => 'SecondB'
            ), 
            array('$set' => array('folder_data.$.otherFolder.$.otherFolder.$.otherFolder' => array('test' => 'sample'))));
4

0 回答 0