MongoDB is a document database, which means it stores data in JSON-like documents, the most natural way to think about data, and is much more expressive and powerful than the traditional row/column model. How about connecting with MongoDB using FireDAC components in your Application and access the dataset to show in a list view? Don’t know where to start? This post will guide you to do that.
MongoDB.ListView Sample App shows how to work with a sample MongoDB Database and show the data in the Listview.
You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Components used in MangoDB.ListView App:
- TFDPhysMongoDriverLink: To link the MongoDB driver to an application and set it up. In general, it is enough to only include the FireDAC.Phys.MongoDB unit into your application uses a clause. The TFDPhysMongoDriverLink component can be used to specify: The VendorHome – the MongoDB installation root folder. The VendorLib – the name and the optional path to the MongoDB client library.
- TFDConnection: To establish a connection to a DBMS and to manage associated datasets.
- TListView: FireMonkey component that you can use to hold and present various types of items.
Before implementing this, as a preliminary step, we need to have a MongoDB Server is running and accessible from your host. 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: You can find the MongoDB Restaurants Demo sample project at:
Object PascalDatabaseFireDACSamplesDBMS SpecificMongoDBRestaurants
- 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.
- Create a select query to retrieve specific documents from the sample MongoDB collection “restaurants” using the TMongoCollection.Find method.
- Parse elements of the selected documents in one of the following ways:
- using the TJSONIterator.Find method.
- using the TJSONIterator.Next, TJSONIterator.Recurse, and TJSONIterator.Return methods.
- using the TJSONIterator.Iterate method.
- Display the retrieved data using the TListView component.
Check out the full article in the DocWiki about the MongoDB.ListView Sample.
Check out the full source code for the MongoDB.ListView projects for Delphi and C++Builder over on GitHub.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Doesn’t work. There is no TFDPhysMongoDriverLink component and no FireDAC.Phys.MongoDB unit.