FireDAC.Phys.MongoDBWrapper.TMongoQuery

Delphi
TMongoQuery = class(TInterfacedObject, IMongoCursor)
C++
class PASCALIMPLEMENTATION TMongoQuery : 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 query builder.
The builder key methods, such as Project, Match, or Sort, return subbuilders for corresponding query parts.
You can use a TMongoQuery object in the following scenarios:
- Create the query object explicitly and submit it to the TMongoCollection.Find or TMongoCollection.Count method.
- In this scenario, you can reuse the query object.
 
- Obtain the query object from an overloaded TMongoCollection.Find or TMongoCollection.Count method, and then cast it to IMongoCursor to execute a query and get a result set cursor.
Examples
To clarify, consider the following examples. These code snippets illustrate how to fetch specific records from the 'restaurants' collection in the 'test' database.
Delphi:
var
  FDConnection1: TFDConnection;
  oCon: TMongoConnection;
  oCrs : IMongoCursor;
begin
  oCon:= TMongoConnection(FDConnection1.CliObj);
  oCrs := oCon['test']['restaurants'].Find
    .Match
      .Add('cuisine', 'Italian')
      .Add('address.zipcode', '10075')
    .&End
    .Sort
      .Field('Name', True)
    .&End
    .Limit(5);
end;
C++Builder: 
  TFDConnection *FDConnection1;
  TMongoConnection *oCon = static_cast<TMongoConnection*>(FDConnection1->CliObj);
  _di_IMongoCursor  oCrs;
  oCrs = interface_cast<IMongoCursor>(oCon->Databases["test"]->Collections["restaurants"]->Find()
    ->Match()
      ->Add("cuisine","Italian")
      ->Add("address.zipcode", "10075")
    ->End()
    ->Sort()
      ->Field("Name",true)
    ->End()
    ->Limit(5));