In this video, we'll demonstrate how you can bind a DevExpress report to our new MongoDB data source
in the Visual Studio Report Designer.
First, let's add a new blank report to our project.
Then, let's invoke the Data Source Wizard
Select MongoDB and click Next.
The first Wizard page prompts you to install the MongoDB.Driver package if it is not installed yet.
Let's check the first option to allow the Wizard to install the package and click Next.
The next Wizard page asks you to specify connection properties to connect to your MongoDB instance.
Here, you can paste a connection string or enter connection fields individually.
You can specify a hostname, port, enable the SRV record option if you want to use an SRV record
and specify authentication credentials if your MongoDB instance requires them.
In our example, we will use a connection string.
Let's paste it in the editor and click Next.
The following Wizard page allows you to save your connection string to the project's configuration file.
Let's enter a name for this connection string...
and click Next.
On the next Wizard page, you can configure queries to your MongoDB instance.
You can choose databases and collections from which you want to retrieve data.
In our example, we will retrieve data from the Northwind database.
Let's select it in the Database column.
In the collection column, let's choose its Products collection.
For each query, you can create a filter condition.
As an example, let's specify a condition for our query that retrieves all not discontinued products.
The Alias column might be useful if you want to retrieve data from the collections with identical names.
In this case, you can assign different names for these collections in this column.
Let's choose the Northwind database and the Products collection again
and specify a filter condition that retrieves all products whose price is less than 20.
Now, let's name the first query as ProductsNotDiscontinued
and the second one as ProductsPriceLt20.
and click Finish.
You can see that the new data source appears in the Field List, and you can now bind report controls to the collection fields.
If you right-click the data source node, you will invoke a menu
which allows you to do different actions with the data source.
For example, you can reconfigure connection properties and queries.
As an example, let's click Manage Queries and add one more query.
Let's select the Northwind database
choose its Customers collections
and click Finish.
You can see that the collections appears in the Field List.
Now, let's create a simple report that displays the names and prices of all not discontinued products.
Then, let's open the report's Preview to show the result.
So, that is how you can bind a report to a MongoDB instance in the Report Designer.
In the same way, you can do it in code.
For this, you just need to use our Reporting API and repeat the same steps as in the Data Source Wizard.
You should specify connection parameters, create queries, and then create a MongoDBDataSource object
and assign the connection parameters and queries to the corresponding data source's properties.
Then, you can can create a report, configure its DataSource and DataMember properties
and reference the fields from the data source in the controls' expressions.
As an example
we created a simple report that displays the names of all products from the Northwind database whose price is less than 10.
Let's open the report's Preview to show the result.
And that's it for this video. If you liked it, please give us a thumbs up. Or you can post questions and comments below.
And don't forget to subscribe and ring the bell so you get notified whenever DevExpress releases new content.
Thanks for watching. And Thank you for choosing DevExpress.