2010-07-08 50 views
0

我有以下对象存储在MongoDB的帮助:MongoDB的 - 用PHP查询

[_id] => MongoId Object (
) 
[horses] => Array (
    [0] => Array (
     [name] => Youve Been Mowed 
     [selectionId] => 3004097 
    ) 
    [1] => Array (
     [name] => Rascal In The Mix 
     [selectionId] => 3460932 
    ) 
    [2] => Array (
     [name] => Clumber Place 
     [selectionId] => 2986884 
    ) 
    [3] => Array (
     [name] => Pretty Orchid 
     [selectionId] => 2581717 
    ) 
    [4] => Array (
     [name] => Astrodonna 
     [selectionId] => 2568095 
    ) 
    [5] => Array (
     [name] => Just Sam 
     [selectionId] => 2511403 
    ) 
    [6] => Array (
     [name] => Many Welcomes 
     [selectionId] => 2866423 
    ) 
    [7] => Array (
     [name] => Two Turtle Doves 
     [selectionId] => 3857873 
    ) 
    [8] => Array (
     [name] => Piquante 
     [selectionId] => 3372813 
    ) 
    [9] => Array (
     [name] => Nimmys Special 
     [selectionId] => 3066557 
    ) 
) 
[marketId] => 101531031 
[marketName] => 7f Hcap 

现在我想添加一个新的领域:

[_id] => MongoId Object (
) 
[horses] => Array (
    [0] => Array (
     [name] => Youve Been Mowed 
     [selectionId] => 3004097 
     [odds] => Array(
      10000000 => 1.5 
      10000020 => 1.6 
      10000030 => 1.7 
     ) 
    ) 
    ... 
    etc. 
    ... 

的100000XX是一个时间戳和1.X是赔率

我真的把我的头撞到桌子上。任何建议非常感谢。

这里是我的声发射(错误):

foreach($horses as &$horse) 
{ 
    $newdata=array('$set'=>array($horse['odds']=>$price)); 
    $filter=array("marketId"=>$marketId); 
    $c->update($filter,$newdata); 
} 

回答

0

非常感谢您的回复。你是来自CPAN上MongoDB Perl模块的Kristina吗? :)

这是我的工作代码:

 $data_object=null; 
     for($i=0;$i<sizeof($horses);$i++) 
     { 
       $data_object->timestamp=$time; 
       $data_object->niceTime=date("c"); 
       $data_object->price=$price; 

       $this_horse=$horses[$i]; 
       if($this_horse['selectionId']==$horseId) 
       { 
         $newdata=array('$push'=>array("horses.$i.odds"=>$data_object)); 
         $filter=array(); 
         $options=array('upsert'=>true); 
         $c->update($filter,$newdata,$options); 
       } 
     } 
+0

是的,我也是克里斯蒂娜。 – kristina 2010-07-08 16:18:51