0

如何使用php在mongodb中插入内部数组我在sheel中运行这个命令然后它运行

db.domain_data.update({"email":"rohan@walkover.in","url.tlds":".com"},{'$addToSet':{"url.$.domain":{"name":"rohan","status":"yes"}}}})

但我用php编写这段代码然后它不起作用

<?
    $domain=array("name"=>"asvdsfs","status"=>"yes");
    $condition=array("email"=>"rohan@walkover.in","url"=>array("tlds"=>".com"));
    $arr=array('$addToSet'=>array("url.$.domain"=>array($domain)));
    //$arr=array('$addToSet'=>array("url"=>array("$"=>array("domain"=>array($domain)))));
    //Above line also not working.
    $status=$db->domain_data->update($condition,array($arr));
?>

如何编写上面运行正确的 php 代码?

4

1 回答 1

0

我想你可能有额外的数组

<?     
      $domain=array("name"=>"asvdsfs","status"=>"yes");     
      $condition=array("email"=>"rohan@walkover.in","url.tlds"=>".com");//1 more change//,"url"=>array("tlds"=>".com")          
      $arr=array('$addToSet'=>array("url.$.domain"=>$domain));    // change this line 
      //$arr=array('$addToSet'=>array("url"=>array("$"=>array("domain"=>array($domain)))));     
      //Above line also not working.     
      $status=$db->domain_data->update($condition,$arr);   // change this line 

?> 
于 2012-04-09T08:32:01.907 回答