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

Hello All, I have a script that gets data from mongo. Before upgrading mongo to 3.2 and used the old connection method with MongoDB::Connection module, then I have never got the following error: MongoDB::NetworkTimeout: Timed out while waiting for socket to become ready for reading I'm using the following connection method: ...
use MongoDB; my $database_server ="<IP>"; my $database_port = "<port>"; my $username = "<username>"; my $password = "<password>"; my $database_name = "<database>"; my $conn = MongoDB::MongoClient->new( host => $database_server, port => $database_port, db_name => $database_name, username=> $username, password => $password, connectTimeoutMS => -1, socketTimeoutMS => -1, ); my $out = $db->get_collection('<collection>')->find(...); $out->immortal(1); ...
Currently I'm using MongoDB 1.4.0 perl driver and Mongo 3.2.6 server What am I doing wrong ? Thanks Logo

Replies are listed 'Best First'.
Re: Mongodb query always quit with error
by 1nickt (Canon) on May 18, 2016 at 12:47 UTC

    Hi Logo,

    I've not used this module myself, but is it possible you have your connection attributes named wrong? From the docs for MongoDB::MongoClient:

    connect_timeout_ms This attribute specifies the amount of time in milliseconds to wait fo +r a new connection to a server. The default is 10,000 ms. If set to a negative value, connection operations will block indefinit +ely until the server replies or until the operating system TCP/IP sta +ck gives up (e.g. if the name can't resolve or there is no process li +stening on the target host/port). A zero value polls the socket during connection and is thus likely to +fail except when talking to a local process (and perhaps even then). This may be set in a connection string with the 'connectTimeoutMS' opt +ion.
    So it looks like you can use 'connectTimeoutMS' in a connection string, but you have to use 'connect_timeout_ms' attribute directly.

    Hope this helps!


    The way forward always starts with a minimal test.
      Thanks :D That could be the problem. I changed the option and started the script yesterday. I didn't get any error and the script could collect all data. Thanks