Skip to main content
All docs
V24.1

MongoDBDataSourceBase.ConnectionName Property

Stores the name of a MongoDB connection string specified in a project’s configuration file.

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(ConnectionNameTypeConverter))]
public string ConnectionName { get; set; }

Property Value

Type Description
String

The name of a MongoDB connection string specified in a project’s configuration file.

Remarks

A MongoDB data source requires a configured connection to a MongoDB instance. To use a connection string from a project’s configuration file to connect to the MongoDB instance, set the ConnectionName property to the name of this connection string. You can also implement a custom connection service and load a connection string by its name from a different file. Refer to the LoadConnection(String) method description for more details.

Example

The example below demonstrates how to use the MongoDBDataSource class to bind an application/component to a MongoDB instance. The example assigns the name of a connection string from a project’s configuration file to the class ConnectionName property to use this string to connect to a MongoDB instance and uses the MongoDBQuery class to specify data query to the Products collection of the Northwind database.

using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.MongoDB;
// ...
// Specify the name of a connection string from
// a project's configuration file.
var connectionName = "MongoDBConnection";

// Specify queries to database collections.
var queryProducts = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Products",
};

// Create a MongoDBDataSource object. Assign the name of the
// connection string to the object's ConnectionName property.
// Add the queries to the object's Queries collection.
var mongoDBDataSource = new MongoDBDataSource() {
    ConnectionName = connectionName,
    Queries = { 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.
//...
See Also