2012-08-11 90 views
0

我有这样的结构:perl的MongoDB的复杂结构更新

{ 
    "user" => "xxxx", 
    "position" => 
    { 
    "A1" => { "state" => 'It', region=>"LOM" etc etc..}, 
    "A2" => { .... }, 
    "A3" => { .... }, 
    .... 
    "An" => { .. } 
    } 
} 

插入即可。但更新这个错误:

not a reference at /usr/local/lib/perl/5.12.4/MongoDB/Collection.pm line 376 

我的更新是:

$tbl->update({ 
{ _id => MongoDB::OID->new(value => "$id") }, 
     { '$set' => 
      { 
       "position" => 
       { 
        "A1" => { "state" => "En" } 
       } 
      } 
     } 
}); 

我哪里错了? Thks!

回答

1

我检查的MongoDB ::收集方法更新

sub update { 
    my ($self, $query, $object, $opts) = @_; 
    ... 
} 

MongoDB::Collection

语法更新 update (\%criteria, \%object, \%options?)

的更新源的语法,但你只传递1参数。

$tbl->update(
{ # 1st anonymous hash 
    { _id => MongoDB::OID->new(value => "$id") }, 
    { '$set' => {        
     "position" => {  
      "A1" => { "state" => "En" } 
      } 
     } 
    } 
}); 

因此,我建议你找出方法更新传递的参数。

+0

$ tbl->更新( {_id =>的MongoDB :: OID->新的(值=> “$ ID”)},{ '$组'=> { “位置”=> { “ A1“=> {”state“=>”En“} } } } );谢谢!所以它是正确的! ;) – diema 2012-08-11 11:21:59