All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

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.v21.1.dll

Declaration

[DefaultValue(null)]
[LocalizableCategory(DataAccessStringId.PropertyGridConnectionCategoryName)]
public string ConnectionName { get; set; }

Property Value

Type Default Description
String

null

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