Home:ALL Converter>PHP updating MongoDB sub array

PHP updating MongoDB sub array

Ask Time:2013-02-04T22:13:15         Author:RussellHarrower

Json Formatter

I am wanting to update my sub-array in MongoDB Here is what the MongoDB Collection looks like

    array (
      '_id' => new MongoId("510fb81638fc5d2966000000"),
      'items' => 
      array (
        '0' => 
        array (
          'id' => '510bb69538fc5d0c2d000000',
          'quantity' => '1',
        ),
        '1' => 
        array (
          'id' => '510bca8138fc5d6e38000000',
          'quantity' => '1',
        ),
      ),
      'session' => '1359964785.85203874781',
      'status' => 'cart'
)

I created my form to send the following

however when I try to $set it to mongo

$filter =  array('session' => $_SESSION["redi-Shop"]);
$data2 = array(
                '$set' => array($_POST['items'])
            );
$options = array("upsert" => true);
$collection->update( $filter, $data2, $options );

Nothing seems to update

Author:RussellHarrower,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14688542/php-updating-mongodb-sub-array
Sammaye :

Your set is wrong:\n\n$filter = array('session' => $_SESSION[\"redi-Shop\"]);\n$data2 = array('$set' =>array('items' => array($_POST['items'])));\n\n$options = array(\"upsert\" => true);\n$collection->update( $filter, $data2, $options );\n\n\nI should mention using the $_POST in this way is asking for some one to hack your shopping site.",
2013-02-04T14:32:15
yy