/* The following are examples of special handling for data types. You will want to keep these commented out. */
/* A boolean value in MongoDB may not appear in results with a value of "true" or "false". Instead, if a boolean is set to true, it will be returned as 1; otherwise it may be 0 or a blank value. */
if (isset($doc_content["failed"])) {
$tmp_failed = $doc_content["failed"];
}
/* A timestamp in MongoDB as ISODate("2014-11-09T19:39:16.55Z") will appear in results as "0.55000000 1415561956". To convert to human-readable can use PHP's date function */
if (isset($doc_content["timestamp"])) {
$tmp_timestamp = date("Y-m-d h:i:s", $doc_content["timestamp"]->sec);
}
}
}
else {
print "ERROR: A connection was established but it seems your query did not have any results.<br />\n";
}
}
else {
print "ERROR: " . $mongoDB_error;
}
print "</body>\n";
print "</html>\n";

Example MongoDB Commands

Get the first 5 documents
$mongoDB_results = $mongoDB_collection->find()->limit(5);

Date Searching
Important Note: It is not possible to search a field in MongoDB such as you can do with Php, MySQL and 'BETWEEN'.
That is, the following (as an example) ordinarily has 5 documents in the database for between '2014-12-04 00:00:00' and '2014-12-04 04:40:45' but MongoDB query returns nothing.
Example 1:
$tmp_startdate = new MongoDate(strtotime("2014-12-04 00:00:00")); //0.00000000 1417651200
$tmp_enddate = new MongoDate(strtotime("2014-12-04 04:40:45")); //0.00000000 1417668045
$mongoDB_searchdata = Array(
'timestamp'=>Array(
'$gte'=>$tmp_startdate
,'$lte'=>$tmp_enddate
)
);
$mongoDB_results = $mongoDB_collection->find($mongoDB_searchdata)->limit(5);

In the example below, if a search is more granular such as to a day, then results are returned.
Example 2:
$tmp_startdate = new MongoDate(strtotime("2014-12-04 00:00:00")); //0.00000000 1417651200
$tmp_enddate = new MongoDate(strtotime("2014-12-05 04:40:45")); //0.00000000 1417754445
$mongoDB_searchdata = Array(
'timestamp'=>Array(
'$gte'=>$tmp_startdate
,'$lte'=>$tmp_enddate
)
);
$mongoDB_results = $mongoDB_collection->find($mongoDB_searchdata)->limit(5);