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.
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);
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With