You are trying to sort a meta field, not a regular field name.
The second argument $collection->find()determines which fields of the document that you (do / do not) want to return to the request.
SELECT *... vs SELECT field1, field2 ... SQL.
, MongoDB 2.6 , , $meta. "" ( ). - "" , .
$text , .. , , . - , .
, $text, "textScore". , , :
array("myFieldname" => array('$meta' => 'keyword'))
, (textScore) "score" , $collection->find():
array("score" => array('$meta' => 'textScore'))
, "", , "textScore" $.
, , .
, $meta projection
array('score' => array('$meta' => 'textScore'))
:
<?php
$mc = new MongoClient();
$collection = $mc->selectCollection("myDatabase", "myCollection");
$string = "search string";
$cursor = $collection->find(
array('$text' => array('$search' => $string)),
array('score' => array('$meta' => 'textScore'))
);
$cursor = $cursor->sort(
array('score' => array('$meta' => 'textScore'))
);
foreach($cursor as $document) {
var_dump($document);
}