Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read timed out after reading 0 bytes, waited for 30.000000 seconds in mongodb

Tags:

mongodb

When I am working on above 5,000,000 records in mongodb, it shows this error "Read timed out after reading 0 bytes, waited for 30.000000 seconds" in find() query. Please any one help me.

like image 286
user3807753 Avatar asked Jul 31 '14 05:07

user3807753


2 Answers

In PHP you can set timeout(-1) to your cursor.

PHP Example:

$conn = new MongoClient("mongodb://primary:27017,secondary:27017", array("replicaSet" => "myReplSetName"));
$db = $conn->selectDB(DBname);
$collection = $db->selectCollection(collection);
$cursor = $collection->find();
$cursor->timeout(-1);

Node.js Example:

// Database connect options
var options = { replset: { socketOptions: { connectTimeoutMS : conf.dbTimeout }}};

// Establish Database connection
var conn = mongoose.connect(conf.dbURL, options);
like image 79
Bogdan Le Avatar answered Sep 28 '22 05:09

Bogdan Le


In PHP you could add the parameter socketTimeoutMS to the other parameters of connection string, in this case to 90 seconds.

$conn = new MongoClient("mongodb://primary:27017,secondary:27017", array("socketTimeoutMS" => "90000"));

Greetings!

like image 24
mariofertc Avatar answered Sep 28 '22 04:09

mariofertc