FireDAC.Phys.MongoDBWrapper.TMongoCollection.Aggregate
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 */;
プロパティ
種類 | 可視性 | ソース | ユニット | 親 |
---|---|---|---|---|
function | public | FireDAC.Phys.MongoDBWrapper.pas FireDAC.Phys.MongoDBWrapper.hpp |
FireDAC.Phys.MongoDBWrapper | TMongoCollection |
説明
指定されたパイプラインをコレクションのドキュメントに適用し、その結果にアクセスするためのカーソルを返します。
Aggregate では、2 種類のコーディング スタイルをサポートしています。
クエリ フラグのセットを任意に指定することができます。
例
次の例では、ドキュメントごとに識別子(_id
)としての郵便番号とその郵便番号を持つイタリアン レストランの数(count
)があり、それらのドキュメントが count
フィールドでソートされているドキュメント集約を取得しています。
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();