I'm currently trying to display a query in which I'm trying to sort by a specific column ("epoch_start").
For some reason, I'm able to display the query by using the find() function but whenever I try to use the sort() function, I receive the following error:
Uncaught Error: Call to undefined method MongoDB\Driver\Cursor::sort()
Please find my code below:
<?php
$query2 = array('complete_title' => array('$regex' => 'andrew_marr'));
$cursor = $collection_programs
->find($query2)
->sort(array("epoch_start" => 1));
foreach ($cursor as $doc) {
?>
<tr>
<td><?php echo $doc["pid"] ?></td>
<td><?php echo $doc["start_time"] ?></td>
<td><?php echo $doc["end_time"] ?></td>
<td><?php echo $doc["complete_title"] ?></td>
<td><?php echo $doc["media_type"] ?></td>
<td><?php echo $doc["masterbrand"] ?></td>
<td><?php echo $doc["service"] ?></td>
<td><?php echo $doc["masterbrand"] ?></td>
</tr>
<?php
}
?>
Please can somebody advise?
$regexmeant to be single quoted? In other words, do you mean to pass the literal string: dollar sign followed by the word regex?