Sorting a collection in doctrine2

166 views Asked by At

I've written the following query (that may or may not be efficient, I'm still a newbie):

    $collection     = $this->dm->getConnection()->selectCollection('db_name', 'collection_name');
    $query          = array('array_name' => new \MongoId(id));
    $cursor         = $collection->find($query)->limit(9)->sort('r', 'desc');

I'm trying to sort by an r value that looks like this in the document:

"r": 0.58325652219355106354

but it isn't actually sorting it by that r-value. What am I doing wrong?

1

There are 1 answers

1
ficuscr On BEST ANSWER

Pretty sure sort takes an array argument. Try

->sort(['r' => 'desc]);

I looked it up... http://apigen.juzna.cz/doc/doctrine/mongodb/source-class-Doctrine.MongoDB.Cursor.html#564-585