Skip to main content
All docs

Bind a Dashboard to MongoDB

  • 3 minutes to read

The WinForms Designer allows you to connect to MongoDB in the Data Source Wizard or in code.


The MongoDB.Driver package should be installed in your project to supply MongoDB data at runtime and display MongoDB in the Data Source Wizard.

Create a Data Source in the Data Source Wizard

Follow the steps below to establish a connection to a database:

  1. Click the New Data Source button in the Data Source ribbon tab.


  2. On the first page of the invoked Data Source Wizard dialog, select MongoDB and click Next.

    Data Source Wizard DataBase MongoDB

  3. Specify connection parameters on the next page. You can pass an entire string or enter connection fields individually. Refer to the following topic for information about connection string format and options: Connection String URI Format.

  4. The following page allows you to configure queries. Select databases and collections that you want to load from the MongoDB instance. A string stored in a query’s Collection column is the default name for the query. The names of MongoDB queries should be unique. You can use the Alias column to set unique names for queries in the same collection. To filter queries, add a filter string to the Filter column.

    Data Source Wizard MongoDB specify quueries

Create a Data Source in Code

To connect to MongoDB you need to create a DashboardMongoDBDataSource instance, configure connection parameters and specify data queries. Refer to the sections below for details.

Configure Connection Parameters

Use one of the following ways:

You can specify the following connection parameters:

Assign a database hostname to the MongoDBConnectionParameters.Hostname property.
Assign a database port to the MongoDBConnectionParameters.Port property.
If the hostname contains an SRV record, set the MongoDBConnectionParameters.IsSRVRecord property to true.
Use the MongoDBConnectionParameters.AuthenticationInfo property to specify authentication credentials.

Specify Data Queries

Initialize a MongoDBQuery object and assign the database and collection names to the MongoDBQuery.DatabaseName and MongoDBQuery.CollectionName properties. Use the MongoDBQuery.FilterString property to specify a filter string for data loaded from the MongoDB instance.

A string stored in the CollectionName property is the default name for the query. The names of MongoDB queries should be unique. Use the Alias property to set unique names for queries.

Add the created queries to the Queries collection.

Create a MongoDB Data Source

Create a DashboardMongoDBDataSource object and add it to the Dashboard.DataSources collection.

The following code snippet demonstrates how to bind a dashboard to a DashboardMongoDBDataSource instance:

using DevExpress.DashboardCommon;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.MongoDB;
var dashboard = new Dashboard();

var dataSource = new DashboardMongoDBDataSource() {
    ConnectionParameters = new MongoDBConnectionParameters("localhost", false, 27017)

var queryCategories = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Categories"
var queryProducts = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Products"