dongzipu7517 2016-07-18 12:07
浏览 10
已采纳

我正在使用php将数据推送到mongodb它已成功完成但结构错误。 为什么它生成0对象?

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

enter image description here

IMG-2 I want below output

enter image description here

  • 写回答

1条回答 默认 最新

  • dongshanjin8947 2016-07-18 12:18
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起