mongoDB更新 - 位置$运算符问题的解决方法

时间:2014-12-01 04:58:10

标签: php mongodb positional-operator

我一直在寻找更新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'))));

0 个答案:

没有答案