Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

error catching in mongodb and perl

by praveenchappa (Acolyte)
on Nov 10, 2014 at 05:26 UTC ( #1106660=perlquestion: print w/replies, xml ) Need Help??

praveenchappa has asked for the wisdom of the Perl Monks concerning the following question:

the problem is i need to generate and validate mongo db quiries, iam writing the below module for validating query,i need to get an error message or some trip condition,the name of the collection acually present is 'student' but if i give 'studentgggggg' its not giving any error message ......please help me out

#!/usr/bin/perl use MongoDB; use JSON; use Data::Dumper; my $conn = MongoDB::Connection->new( host => 'xxxxxxx', port => 27017, username=>'xxxx', password=>'xxxx', db_name => 'prav' ); my $database = $conn->get_database( 'prav' ); my $collection = $database->get_collection( 'studenttgggggg'); my $err = $database->last_error(); print Dumper $err; my $data = $collection->find({"id"=>"stu_7"}); my $err = $collection->last_error(); # print %$err; print Dumper $err; #print Dumper $data; while (my $doc = $data->next) { my @qual=@{$doc->{'qualifications'}}; print @qual; print "\n"; }

Replies are listed 'Best First'.
Re: error catching in mongodb and perl
by Loops (Curate) on Nov 10, 2014 at 06:05 UTC

    Hi there,

    From the docs:

    NOTE: MongoDB::Connection is DEPRECATED as of version 0.502.0 of the MongoDB CPAN distribution. It is no longer maintained and will be removed in a future version. Use MongoDB::MongoClient instead.

    But having looked a little closer, the MongoDB::Tutorial is still using the Connection object rather than MongoClient. And doesn't show any error checking...

      i got an error while using MogoDB::MongoClient as below,i tried to install using cpan but its not istalling.

      use MongoDB; use JSON; use Data::Dumper; $client = MongoDB::MongoClient->new( host => 'remote_machine_ip:270 +17'); $client->connect; $client->authenticate('username', 'password', 'authenticationdb'); my $database = $client->get_database('prav'); my $collection = $database->get_collection( 'student'); my $data=$collection->find(); while (my $doc = $data->next) { my @qual=@{$doc->{'qualifications'}}; print @qual; print "\n"; } Can't locate object method "new" via package "MongoDB::MongoClient" (p +erhaps you forgot to load "MongoDB::MongoClient"?) at .. cpan MongoDB::MongoClient ---also tried cpan MongoDB .... .... Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible

        What was the error when trying to install MongoDB::MongoClient? That appears to be the crux of the matter.

        You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1106660]
Approved by boftx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-06-27 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (86 votes). Check out past polls.

    Notices?