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
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