PHP & mongodb query like sql
This is the sql query.
$str = "SELECT DATE(sold_dt) AS dt, COUNT(*) AS count FROM temp GROUP BY DATE(sold_dt) ORDER BY dt desc limit 50"; $query = $this->db->query($str); $data = $query->result_array();
I’d like to use mongodb instead of mysql in my php projects.
$filter = ['sold_dt']; $options = [ 'projection' => ['_id' => 0], 'sort' => ['sold_dt' => -1], 'group' => ['_id' => 'Date(sold_dt)'], 'limit' => 20 ]; $query = new MongoDB\Driver\Query($filter, $options); $cursor = $db->executeQuery($db.".". $tempTable, $query); $data= $cursor->toArray();
I am not sure it is correct and as you can see aggregate is missed. I am going to complete this query. How can I do this using executeQuery() or executeCommand()? Any help is appreciated.