I am following an example from PHP docs to sort some records in a collection:
$cursor = $mongo->party_scores->find()->limit(10); $cursor = $cursor->sort(array("score",-1)); foreach($cursor as $doc) { print_r($doc); }
By doing this, I see documents in random order (not sorted).
But executing this request from the mongo console results in a properly sorted answer:
db.party_scores.find().sort({score : -1 })
I feel that there must be something obvious that I am missing.
source share