FireDAC.Phys.MongoDBWrapper.TMongoPipeline
Delphi
TMongoPipeline = class(TInterfacedObject, IMongoCursor)
C++
class PASCALIMPLEMENTATION TMongoPipeline : public System::TInterfacedObject
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
class | public | FireDAC.Phys.MongoDBWrapper.pas FireDAC.Phys.MongoDBWrapper.hpp |
FireDAC.Phys.MongoDBWrapper | FireDAC.Phys.MongoDBWrapper |
Description
Represents a fluent style MongoDB pipeline builder.
You can use a TMongoPipeline object in the following scenarios:
- Create the pipeline object explicitly and submit it to the TMongoCollection.Aggregate method. In this scenario you can reuse the pipeline object.
- Obtain the pipeline object from an overloaded TMongoCollection.Aggregate method, and then cast it to IMongoCursor to execute a pipeline and get a result set cursor.
You can use the following methods to define stages of the pipeline:
You can also define some options for your pipeline.
Examples
The following code snippets illustrate how to pass a collection into the aggregation pipeline, and then count the number of documents for each borough. The output list is sorted by the count
field.
Note: For more information, see the MongoDB Restaurants sample project.
Delphi:
var
oCrs: IMongoCursor;
oCrs := FCon['test']['restaurants'].Aggregate()
.Group
.Add('_id', '$borough')
.BeginObject('count')
.Add('$sum', 1)
.EndObject
.&End
.Sort('{ count: 1 }').&End;
C++Builder:
di_IMongoCursor oCrs = interface_cast<IMongoCursor>(MongoCon->Databases["test"]->Collections["restaurants"]->Aggregate())
->Group()
->Add("_id", "$borough")
->BeginObject("count")
->Add("$sum", 1)
->EndObject()
->End()
->Sort("{ count: 1 }")->End();