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.

MongoDBDataSource(String) Constructor

Initializes a new instance of the MongoDBDataSource class with specified settings.

Namespace: DevExpress.DataAccess.MongoDB

Assembly: DevExpress.DataAccess.v21.1.dll

Declaration

public MongoDBDataSource(
    string connectionName
)

Parameters

Name Type Description
connectionName String

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

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