FMX.FireDAC.MongoDB.BatchMove Sample
This sample shows how to copy data from a SQLite dataset to a MongoDB dataset in Delphi and C++Builder applications.
Contents
Location
You can find the BatchMove sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and navigate to:
Object Pascal\Database\FireDAC\Samples\DBMS Specific\MongoDB\BatchMove
CPP\Database\FireDAC\Samples\DBMS Specific\MongoDB\BatchMove
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
This sample application illustrates how to work with SQLite and MongoDB databases.
Using this sample application, you can:
- Connect to an SQLite database
- Connect to a MongoDB server
- Copy data records from the specified table in SQLite to a MongoDB database.
Preliminary Steps
Before using the BatchMove sample project, review the following checklist:
- A MongoDB server is running and accessible from your host.
Note: If the MongoDB server is not running on the machine where you want to run this sample application, or requires non-default connection parameters, such as a port other than 27017, configure the FDConnection1 component accordingly. For details, see Connect to MongoDB Database.
How to Use the Sample
To run this project
- Navigate to one of the locations given above and open:
- Delphi:
Mongo_BatchMove.dproj
project file. - C++Builder:
Mongo_BatchMove.cbproj
project file.
- Delphi:
- Press F9 or choose Run > Run.
- Click the Move Data button.
Files
File in Delphi | File in C++ | Contains |
---|---|---|
Mongo_BatchMove.dproj |
Mongo_BatchMove.cbproj |
The project itself. |
fMain.fmx |
fMain.fmx |
The main form where the components are located. |
fMain.pas |
fmain.cpp |
Implementation of the sample. |
Implementation
- The project uses a TFDConnection component to establish a connection with sample databases (SQLite and MongoDB).
- To select the data records from the database, the project uses a TFDMongoQuery, a TFDPhysSQLiteDriverLink, a TDataSource, and a TFDPhysMongoDriverLink components.
- In the TFDBatchMoveSQLDriver.TableName property, the project sets the source table name (Orders in a given case) that contains the data to copy.
- In the TFDBatchMoveDataSetDriver.DataSet property, the project sets the destination dataset (FDMongoQuery1 in a given case) where to copy the data records.
- To copy data from the SQLite database to the MongoDB database, the project calls the TFDBatchMove.Execute method.
- A TDBGrid displays the retrieved data.
Uses
- FireDAC.Comp.Client.TFDConnection
- Vcl.DBGrids.TDBGrid
- TFDMongoQuery
- TFDPhysMongoDriverLink
- TFDBatchMoveSQLDriver
- TFDBatchMoveDataSetDriver
- TFDBatchMove