Clinton Jooooones
Clinton Jooooones

Reputation: 1027

Sorting a collection in doctrine2

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?

Upvotes: 0

Views: 164

Answers (1)

ficuscr
ficuscr

Reputation: 7054

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

Upvotes: 1

Related Questions