MongoCursor::sort

(PECL mongo >=0.9.0)

MongoCursor::sortSorts the results by given fields

说明

public MongoCursor::sort ( array $fields ) : MongoCursor

参数

fields

An array of fields by which to sort. Each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort.

Each result is first sorted on the first field in the array, then (if it exists) on the second field in the array, etc. This means that the order of the fields in the fields array is important. See also the examples section.

返回值

Returns the same cursor that this method was called on.

错误/异常

Throws MongoCursorException if this cursor has started iterating.

范例

Example #1 MongoCursor::sort() example

<?php
// Sort on field x, ascending
$cursor->sort(array('x' => 1));

// The order in the associative array is important. For instance, these two
// examples will yield different results:

// Sort on date ascending and age descending
$cursor->sort(array('date' => 1'age' => -1));

// Sort on age descending and date ascending
$cursor->sort(array('age' => -1'date' => 1));
?>
相关文章
php date/time 函数 get info about given date formatted according to the specified formatphp snmp 函数 fetch the snmp object which follows the given object idphp socket 函数 create and bind to a socket from a given addrinfophp socket 函数 queries the remote side of the given socket which may either result in host/port or in a unix filesystem path dependent on its typephp statistic 函数 calculates any one parameter of the normal distribution given values for the othersphp mongocursor counts the number of results for this queryphp mongocursor checks if there are results that have not yet been sent from the databasephp mongocursor sets the fields for a queryphp mongocursor limits the number of results returnedphp mongocursor if this query should fetch partial results from mongos if a shard is downphp mongocursor skips a number of resultsphp mongocursor sorts the results by given fieldsphp mongocursor sets whether this cursor will be left open after fetching the last resultsphp mysql xdevapi crudoperationsortable sort resultsphp mysql xdevapi sqlstatement check for more resultsphp normalizer gets the decomposition mapping property for the given utf 8 encoded code pointphp sdo das relational 函数 executes a given sql query against a relational database and returns the results as a normalised data graphphp solrdocument sorts the fields in the documentphp solrinputdocument sorts the fields within the documentphp solrquery requests a return of sub results for values within the given facet
关注编程学问公众号