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