DashboardMongoDBDataSource Class
A data source that retrieves data from MongoDB.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.2.Core.dll
Declaration
public class DashboardMongoDBDataSource :
MongoDBDataSourceBase,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IFederationDataProvider,
IQueryDataSource<MongoDBQuery>,
ICloneable<DashboardMongoDBDataSource>,
IAssignable<DashboardMongoDBDataSource>,
IExternalSchemaConsumer
Remarks
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:
Create a MongoDBCustomConnectionParameters object and assign a connection string to the MongoDBCustomConnectionParameters.ConnectionString property.
Assign a MongoDBConnectionParameters instance with specified connection parameters to the MongoDBDataSourceBase.ConnectionParameters property.
You can specify the following connection parameters:
- Hostname
- Assign a database hostname to the MongoDBConnectionParameters.Hostname property.
- Port
- Assign a database port to the MongoDBConnectionParameters.Port property.
- SRVRecord
- If the hostname contains an SRV record, set the MongoDBConnectionParameters.IsSRVRecord property to true.
- Authentication
- 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"
};
dataSource.Queries.Add(queryCategories);
var queryProducts = new MongoDBQuery() {
DatabaseName = "Northwind",
CollectionName = "Products"
};
dataSource.Queries.Add(queryProducts);
dashboard.DataSources.Add(dataSource);