title: Insert into mongodb with perl
body: <p>I wrote a script to insert items into <a href="http://search.cpan.org/dist/MongoDB/lib/MongoDB.pm" rel="nofollow">mongodb</a></p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  use MongoDB;
  use Data::Dumper;
  
  my $hostname = "localhost";
  my $port = 27017;
  
  my $conn = MongoDB::Connection-&gt;new( "host" =&gt; "$hostname", 
                                       "port" =&gt; $port );
  my $db = $conn-&gt;test;
  my $user_stats = $db-&gt;test_stats;
  
  # Insert line
  $user_stats-&gt;insert({'user_id' =&gt; 123, 
                       'pointA'=&gt; 12, 
                       'pointB' =&gt; 13, 
                       'total' =&gt; 25, } );
  
  my $myStr = $user_stats-&gt;find_one();
  print Dumper($myStr);
  </code></pre>
  
  <p>The code work well.
  However when I change to <code>insert line</code> to</p>
  
  <pre><code>my $a = "{'user_id' =&gt; 123, 
            'pointA' =&gt; 12,
            'pointB' =&gt; 13,
            'total' =&gt; 25}";
  
  $user_stats-&gt;insert($a);
  </code></pre>
  
  <p>It doesn't work given back error:<code>not a reference at /usr/local/lib/perl5/site_perl/5.12.3/sun4-solaris/MongoDB/Collection.pm line 296.</code></p>