David Duman
David Duman

Reputation: 6656

MongoDB PHP Driver: Limit option has no effect

The code is like this, and the limit & sort have no effect, the query returns all the records that fit the filter.

$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$query = new MongoDB\Driver\Query( ['isSent' => false] );
$options = array('sort' => array('priority', 1), 'limit' => 10 );
$dt = $m->executeQuery("db.emails", $query, $options);

foreach($dt as $row) {
   // do something
}

Am I missing something?

Upvotes: 0

Views: 249

Answers (1)

dnickless
dnickless

Reputation: 10918

Try this instead:

$query = new MongoDB\Driver\Query( ['isSent' => false], ['sort' => ['priority' => 1], 'limit' => 10]);
$dt = $m->executeQuery("db.emails", $query);

Upvotes: 1

Related Questions