FireDAC.Phys.MongoDBWrapper.TMongoCollection.Aggregate

De RAD Studio API Documentation
Aller à : navigation, rechercher

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 */;

Propriétés

Type Visibilité  Source Unité  Parent
function public
FireDAC.Phys.MongoDBWrapper.pas
FireDAC.Phys.MongoDBWrapper.hpp
FireDAC.Phys.MongoDBWrapper TMongoCollection


Description

Applique le pipeline spécifié aux documents de la collection et renvoie un curseur pour accéder aux résultats.

Aggregate prend en charge deux styles de codage différents.

Facultativement, vous pouvez spécifier un ensemble d'indicateurs de requête.

Exemple

L'exemple suivant obtient une agrégation de documents où chaque document contient un code postal comme identificateur (_id) et le nombre de restaurants italiens correspondant à ce code postal (count), triés selon le champ count.

Shell MongDB :

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();

Voir aussi