FireDAC.MongoDB.ListView Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample shows how to work with a sample MongoDB dataset in a Delphi application.


You can find the ListView sample project at:


This sample application illustrates how to connect to a MongoDB server, select specific documents from a sample collection "restaurants" using a select query, parse the selected document elements (JSON items), and then display the results using the TListView component.

Using this sample application, you can:

Preliminary Steps

Before using this 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.

  • The "restaurants" collection of the "test" database is provisioned with test data. To provision this collection, run the MongoDB Restaurants Demo, and click the Load Data button:
MongoDB Restaurants Demo.png

You can find the MongoDB Restaurants Demo sample project at:

How to Use the Sample

To run this project and select required data records

  1. Navigate to one of the locations given in the Location section above and open:
    • Delphi: Mongo_DataSet.dproj project file.
  2. Press F9 or choose Run > Run.
  3. To display the elements of the selected documents, click one of the following buttons:
    • Read using Find: selects all Italian restaurants from Manhattan, and then finds the required elements in a document using the TJSONIterator.Find method.
    • Read using Next/Recurse/Return: selects all Italian restaurants from Manhattan, and then iterates through the document elements using the TJSONIterator.Next/Recurse/Return methods. This allows the application to analyze each element (a JSON item) and find the required items in the elements tree.
    • Read using Iterate: selects all restaurants from Brooklyn, and then iterates through the document elements using the TJSONIterator.Iterate method. For each element, the TJSONIterator.Iterate method calls a callback function.

MongoDB ListView.png


File in Delphi File in C++ Contains



The project itself.



The main form where the components are located.



Implementation of the sample.


  • The project uses a TFDConnection component to establish a connection to a sample database.
  • To select specific documents from a sample database, the project uses the TMongoCollection.Find method.
  • To parse elements of the selected documents, the project uses various methods of TJSONIterator.
  • A TListView component displays the retrieved and parsed data.


See Also