No results with PHP search in MongoDB? -
i have database store dns logs. data stored in collection dnslog
. document structure:
{ "_id" : objectid("53539df1e4b076aa8975840a"), "dateandtime" : isodate("2014-04-09t03:42:48z"), "client" : "222.29.72.224", "query" : "www.google.com", "other" : "aaaa" }
i stored week's log database , total count 821943936; have following php script search results:
$m = new mongoclient(); echo "connection database successfully"."<br />"; $db = $m->dns; echo "datebase dns selected"."<br />"; $collection = $db->dnslog; echo "collection selected succsessfully"."<br />"; $startdate = new mongodate("2014-04-09 11:42:00"); $enddate = new mongodate("2014-04-09 11:43:00"); $result = $collection->find(array("dateandtime"=>array('$gte'=>$startdate,'$lte'=>$enddate))); echo $result->count(); foreach($result $doc){ echo $doc['client']."<br />"; }
the script not return results. output script.
connection database datebase dns selected collection selected succsessfully
i'm sure in have documents specified query because can see document when use:
db.dnslog.find();
your query wrong. mongodate expecting unix timestamp parameter in constructor:
$startdate = new mongodate(strtotime("2014-04-09 11:42:00")); $enddate = new mongodate(strtotime("2014-04-09 11:43:00"));
Comments
Post a Comment