MongoDBDataSourceBase.ConnectionParameters Property
Stores MongoDB connection parameters.
Namespace: DevExpress.DataAccess.MongoDB
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
[LocalizableCategory(DataAccessStringId.PropertyGridConnectionCategoryName)]
[TypeConverter(typeof(MongoDBDataSourceBase.ConnectionParametersTypeConverter))]
public MongoDBConnectionParametersBase ConnectionParameters { get; set; }
Property Value
Type | Description |
---|---|
MongoDBConnectionParametersBase | MongoDB connection parameters. |
Remarks
A MongoDB data source requires configured connection to a MongoDB instance. Use the ConnectionParameters property to specify a connection string or assign connection fields individually.
- To specify a connection string, create a MongoDBCustomConnectionParameters object and assign the connection string to the object’s ConnectionString property.
- To assign connection fields individually, create a MongoDBConnectionParameters object and assign the hostname and port of the MongoDB instance to the object’s Hostname and Port properties. Enable the object’s IsSRVRecord property if the hostname contains an SRV record. Use the object’s AuthenticationInfo property to specify authentication credentials.
To use the created parameters for the MongoDBDataSource object, assign the parameters to the object’s ConnectionParameters property.
Example
The example below demonstrates how to use the MongoDBDataSource class to bind an application or component to a MongoDB instance. The example uses the MongoDBConnectionParameters class to specify connection parameters to the MongoDB instance, the MongoDBPasswordAuthenticationInfo class to specify connection credentials, and the MongoDBQuery class to create data queries to the Categories and Products collections of the Northwind database.
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.MongoDB;
// ...
var MongoDBPasswordAuthInfo = new MongoDBPasswordAuthenticationInfo(
username: "name",
password: "password",
authenticationDatabase: "admin"
);
// Create a MongoDBConnectionParameters object and
// specify connection parameters to a MongoDB instance.
var connectionParameters = new MongoDBConnectionParameters(
hostName: "localhost",
isSRV: false,
port: 27017,
info: MongoDBPasswordAuthInfo
);
// Specify queries to database collections.
var queryCategories = new MongoDBQuery() {
DatabaseName = "Northwind",
CollectionName = "Categories",
};
var queryProducts = new MongoDBQuery() {
DatabaseName = "Northwind",
CollectionName = "Products",
};
// Create a MongoDBDataSource object. Assign the created connection
// parameters to the object's ConnectionParameters property. Add the
// queries to the object's Queries collection.
var mongoDBDataSource = new MongoDBDataSource() {
ConnectionParameters = connectionParameters,
Queries = { queryCategories, queryProducts },
};
// Call the Fill method of the MongoDBDataSource object to execute the
// queries and load data from the MongoDB instance.
mongoDBDataSource.Fill();
// Use the created object as a data source in your application or component.
// ...
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.MongoDB
' ...
Dim MongoDBPasswordAuthInfo = New MongoDBPasswordAuthenticationInfo(username:="name", password:="password", authenticationDatabase:="admin")
' Create a MongoDBConnectionParameters object and
' specify connection parameters to a MongoDB instance.
Dim connectionParameters = New MongoDBConnectionParameters(hostName:="localhost", isSRV:=False, port:=27017, info:=MongoDBPasswordAuthInfo)
' Specify queries to database collections.
Dim queryCategories = New MongoDBQuery() With {
.DatabaseName = "Northwind",
.CollectionName = "Categories"
}
Dim queryProducts = New MongoDBQuery() With {
.DatabaseName = "Northwind",
.CollectionName = "Products"
}
' Create a MongoDBDataSource object. Assign the created connection
' parameters to the object's ConnectionParameters property. Add the
' queries to the object's Queries collection.
Dim mongoDBDataSource = New MongoDBDataSource() With {
.ConnectionParameters = connectionParameters
}
mongoDBDataSource.Queries.Add(queryCategories)
mongoDBDataSource.Queries.Add(queryProducts)
' Call the Fill method of the MongoDBDataSource object to execute the
' queries and load data from the MongoDB instance.
mongoDBDataSource.Fill()
' Use the created object as a data source in your application or component.
' ...