0

我有这个结构:

{
  "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" }
                }
           }
        }
});

我哪里错了?谢谢!

4

1 回答 1

1

我检查MongoDB::Collection更新源的语法

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

MongoDB::Collection 内部方法更新

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

但你只传递了 1 个参数。

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

所以我建议你通过传递参数来计算方法更新。

于 2012-08-11T11:08:04.337 回答