2012-08-11 94 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