Query MongoDB via PHP, compare date and send email -


i want query on users in database. check 'lastlogin' of each user , if longer ago e.g. 7 days, send mail mail address of user. did simple query already, have no idea how continue. array notation confuses me...

hope can me out or post code snippet!

<?php    $m = new mongo();  $collection = $m->selectdb('platte')->selectcollection('users');    $results = $collection->find(array(),array("email"=>1, "lastlogin"=>2));    ?>

you looking range query. create mongodate, example using strtotime(), represents date 7 days ago , use in search query searching documents login field less 7 days ago date:

in mongo shell, represented query:

var d = new date(); d.setdate(d.getdate() - 7);  var query = {     "lastlogin": {         "$lte": d     } }; var projection = {     "email": 1,     "lastlogin": 1 }  db.users.find(query, projection); 

in php, translate to:

$m = new mongo(); $collection = $m->selectdb('platte')->selectcollection('users');  $d = new mongodate(strtotime(date("y-m-d h:i:s","-7 days"))); $searchcriteria = array(     "lastlogin" => array(         "$lte" => $d     ),     ); $projection = array(     "email" => 1,      "lastlogin" => 1 );  $results = $collection->find($searchcriteria, $projection); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -