CollectionFind::sort

(No version information available, might only be in Git)

CollectionFind::sortSet the sorting criteria

Beschreibung

public mysql_xdevapi\CollectionFind::sort(string $sort_expr): mysql_xdevapi\CollectionFind

Sort the result set by the field selected in the sort_expr argument. The allowed orders are ASC (Ascending) or DESC (Descending). This operation is equivalent to the 'ORDER BY' SQL operation and it follows the same set of rules.

Parameter-Liste

sort_expr

One or more sorting expressions can be provided. The evaluation is from left to right, and each expression is separated by a comma.

Rückgabewerte

A CollectionFind object that can be used to execute the command, or to add additional operations.

Beispiele

Beispiel #1 mysql_xdevapi\CollectionFind::sort() example

<?php
$session 
mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

$schema $session->getSchema("addressbook");
$create $schema->createCollection("people");
$create
  
->add('{"name": "Alfred", "age": 18, "job": "Butler"}')
  ->
execute();
$create
  
->add('{"name": "Reginald", "age": 42, "job": "Butler"}')
  ->
execute();

// ...

$collection $schema->getCollection("people");

$result $collection
  
->find()
  ->
sort('job desc''age asc')
  ->
execute();

var_dump($result->fetchAll());
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

array(2) {
  [0]=>
  array(4) {
    ["_id"]=>
    string(28) "00005b6b53610000000000000106"
    ["age"]=>
    int(18)
    ["job"]=>
    string(6) "Butler"
    ["name"]=>
    string(6) "Alfred"
  }
  [1]=>
  array(4) {
    ["_id"]=>
    string(28) "00005b6b53610000000000000107"
    ["age"]=>
    int(42)
    ["job"]=>
    string(6) "Butler"
    ["name"]=>
    string(8) "Reginald"
  }
}

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Laufschrift mit Bildern

This is a test This is a test ...

Geschrieben von Kristy am 24.01.2026 17:54:44
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS
SEO-URLs und MySQL

If you spend the money you would have used on a BBW love doll (https://www.sexdollpartner.com/collections/bbw-sex-doll) to see a doctor at night, ...

Geschrieben von starsmart1512a am 24.01.2026 10:56:28
Forum: SQL / Datenbanken
variables Bild incl. Text mit PHP für eine Schleifenausgabe erstellen

Generating images dynamically in PHP with a loop becomes much cleaner once the process is treated as structured output rather than random drawing. ...

Geschrieben von jonsmith86 am 24.01.2026 07:24:48
Forum: PHP Developer Forum
Verkauf Existenz für Gründer/Agentur

Selling a business as a founder or agency usually comes down to clean numbers, clear operations, and a brand that can keep performing without the ...

Geschrieben von jonsmith86 am 24.01.2026 07:20:57
Forum: Existenzgründer, Freelancing, Verträge und sonstiges