php code:
$data = array('$push' => array("scap" => array(
"loan" => array(array("user_profile_id"=>"","current_gross_loan"=>$userScapData['OutstandingLoans'],"_id"=>"","details"=>array())),
"tax" => array(array("user_profile_id"=>"","current_gross_income"=>$userScapData['Tax'],"_id"=>"","details"=>array())),
"essentials" => array(array("user_profile_id"=>"","current_gross_essentials"=>$userScapData['Essentials'],"_id"=>"","details"=>array())),
"lifesyle" => array(array("user_profile_id"=>"","current_gross_lifestyle_annual"=>$userScapData['LifestyleAnnual'],"current_gross_lifestyle_lumpsum"=>$userScapData['LifestyleLumpsum'],"_id"=>"","details"=>array())),
"responsibility" => array(array("user_profile_id"=>"","current_gross_responsibility_annual"=>$userScapData['ResponsibilityAnnual'],"current_gross_responsibility_lumpsum"=>$userScapData['ResponsibilityAnnual'],"_id"=>"","details"=>array())),
"legacy" => array(array("user_profile_id"=>"","current_gross_legacy"=>$userScapData['Legacy'],"_id"=>"","details"=>array())),
"cahrity" => array(array("user_profile_id"=>"","current_gross_charity_percentage"=>"","current_gross_charity_purchase"=>$userScapData['Charity'],"_id"=>"","details"=>array())),
"real_estate" => array(array("user_profile_id"=>"","current_gross_real_estate_monthly"=>$userScapData['RealEstateMonthly'],"current_purchase_amount"=>$userScapData['RealEstatePurchase'],"_id"=>"","details"=>array()))
)
));
$userScapCol = $db->user_scenarios;
$_id = new MongoId($userScapData['ScenarioId']);
$userScapCol->update(array("_id"=>$_id),array('$push' => $data));
**IMG-1**
**My output:-**
Its generating 0 object why i don't know i want output like IMG-2. what is wrong in my array
IMG-2 I want below output
$push
as of programming languages, appends to an array.
If the field is absent in the document to update, $push adds the array field with the value as its element.
To add document of structure you have, you need just to insert, or uprade without $push
:
$userScapCol->update(array("_id"=>$_id), $data['$push']);
Anyway check twice, because you are sending in your original request:
array('$push' => array('$push' => array(/* ... */)))
what may behave odd.