FireDAC.Phys.MongoDBWrapper.TMongoCollection.Aggregate

Aus RAD Studio API Documentation
Wechseln zu: Navigation, Suche

Delphi

function Aggregate(APipeline: TMongoPipeline; AFlags: TMongoQueryFlags = []): IMongoCursor; overload;
function Aggregate(AFlags: TMongoQueryFlags = []): TMongoPipeline; overload;

C++

_di_IMongoCursor __fastcall Aggregate(TMongoPipeline* APipeline, TMongoQueryFlags AFlags = TMongoQueryFlags() )/* overload */;
TMongoPipeline* __fastcall Aggregate(TMongoQueryFlags AFlags = TMongoQueryFlags() )/* overload */;

Eigenschaften

Typ Sichtbarkeit Quelle Unit Übergeordnet
function public
FireDAC.Phys.MongoDBWrapper.pas
FireDAC.Phys.MongoDBWrapper.hpp
FireDAC.Phys.MongoDBWrapper TMongoCollection


Beschreibung

Wendet die angegebene Pipeline auf Dokumente der Sammlung an und gibt einen Cursor für den Zugriff auf die Ergebnisse zurück.

Aggregate unterstützt zwei verschiedene Programmierstile.

Sie können optional eine Menge von Abfrage-Flags angeben.

Beispiel

Das folgende Beispiel ruft eine Aggregation von Dokumenten ab, wobei jedes Dokument über einen PLZ-Code als Bezeichner (_id) und die Anzahl italienischer Restaurants in diesem PLZ-Bereich (count), sortiert nach dem Feld count, verfügt.

MongDB-Shell:

db.restaurants.aggregate([
    { $match: { cuisine: "Italian" } },
    { $group: { _id: "$address.zipcode", count: { $sum: 1 } } },
    { $sort: { count: -1 } }
])

Delphi:

MyCursor := MyCollection.Aggregate
  .Match
    .Add('cuisine', 'Italian')
  .&End
  .Group
    .Add('_id', '$address.zipcode')
    .BeginObject('count')
      .Add('$sum', 1)
    .EndObject
  .&End
  .Sort('{ count: -1 }').&End;

C++:

_di_IMongoCursor MyCursor = MyCollection->Aggregate()
  ->Match()
    ->Add("cuisine", String("Italian"))
  ->End()
  ->Group()
    ->Add("_id", String("$address.zipcode"))
    ->BeginObject("count")
      ->Add("$sum", 1)
    ->EndObject()
  ->End()
  ->Sort("{ count: -1 }")->End()
  ->Open();

Siehe auch