Hi,
I'm having a problem with fetching and printing results from MongoDB (2.2.1) using PHP.
I can print the results just fine if I can match the 100 results (limit) in below 60 seconds (timeout). The problem is that if I have matches here and there in database, and the 60 second timeout is reached then nothing is printed.
I was wondering if and how it is possible to print (even the part of the results) when the timeout is reached. The database is quite large with two db's with over 37 million entries each, running on 4 core xeon and 16gb RAM.
I'm not worried about the fact that I might not reach the end of database with the limited time, it is not really crucial. I would just like to output the results already found when the timelimit is reached...
Below are main points of the PHP-script:
<?php
/////////////////////////////////
// Connect to database
$conn = new Mongo();
// Select a database
$db = $conn->messages;
// Select a collection
$collection = $db->logging;
/////////////////////////////////
/////////////////////////////////
// Define searchbase
$search_base = array('SDATA.destination-port' => $search_destinationport);
$search_base['SDATA.destination-address'] = $search_destinationip;
$search_base['SDATA.policy-name'] = $search_policyid;
$cursor = $collection->find($search_base)->sort(array('$natural' => -1))->limit(100)->timeout(60000);
/////////////////////////////////
try {
foreach ($cursor as $obj) {
echo $obj['DATE'];
foreach ($obj['SDATA'] as $key => $result) {
echo $result;
}
}
}
catch(MongoCursorTimeoutException $e) {
echo "No match in database";
}
// Close MongoDB connection
$conn->close();
?>