FireDAC.Phys.MongoDBDataSet.TFDMongoQuery

From RAD Studio API Documentation
Jump to: navigation, search

FireDAC.Phys.MongoDBDataSet.TFDMongoCustomDataSetFireDAC.Phys.MongoDBDataSet.TFDMongoCustomMemTableFireDAC.Comp.Client.TFDCustomMemTableFireDAC.Comp.Client.TFDAdaptedDataSetFireDAC.Comp.DataSet.TFDDataSetTFDMongoQuery

Delphi

TFDMongoQuery = class (TFDMongoCustomDataSet)

C++

class PASCALIMPLEMENTATION TFDMongoQuery : public TFDMongoCustomDataSet

Properties

Type Visibility Source Unit Parent
class public
FireDAC.Phys.MongoDBDataSet.pas
FireDAC.Phys.MongoDBDataSet.hpp
FireDAC.Phys.MongoDBDataSet FireDAC.Phys.MongoDBDataSet

Description

The TFDMongoQuery class is used to execute a MongoDB query.

You can specify a query in one of the following ways:

  • Using the QProject, QMatch, and QSort properties at design-time or run-time.
  • Using the Query Builder provided by the Query property at run-time.

To execute a query, specify the Connection, DatabaseName, and CollectionName properties.

Examples

To clarify, consider the following examples. These code snippets illustrate how to fetch specific records from the 'restaurants' collection in the 'test' database.

Note: These code snippets are extracted from the MongoDB DataSet sample project. For detailed description of this sample, see MongoDB.DataSet sample.

Delphi:

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  // Setting the Mode to fmAll helps you measure the fetch performance
  FDMongoQuery1.FetchOptions.Mode := fmAll;
  // Setting the CachedUpdates to True helps you measure the update performance
  FDMongoQuery1.CachedUpdates := True;
end;

// This event handler executes a query specified in the FDMongoQuery1.QMatch property.  
procedure TfrmMain.Button1Click(Sender: TObject);

begin
    FDMongoQuery1.Close;
    FDMongoQuery1.QMatch := '{"cuisine": "Italian", "address.zipcode": "10075"}';
    FDMongoQuery1.Open;
// ......
end;

C++Builder:

  void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
	// Setting the Mode to fmAll helps you measure the fetch performance
	FDMongoQuery1->FetchOptions->Mode << fmAll;
	// Setting the CachedUpdates to True helps you measure the update performance
	FDMongoQuery1->CachedUpdates = true;
}
//---------------------------------------------------------------------------
// This event handler executes a query specified in the FDMongoQuery1->QMatch property. 
void __fastcall TfrmMain::Button1Click(TObject *Sender)
{
	        FDMongoQuery1->Close();
		FDMongoQuery1->QMatch = "{'cuisine': 'Italian', 'address.zipcode': '10075'}";
		FDMongoQuery1->Open();
// .....
}

See Also