Skip to main content
All docs

MongoDBDataSource(String) Constructor

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

Namespace: DevExpress.DataAccess.MongoDB

Assembly: DevExpress.DataAccess.v22.2.dll

NuGet Package: DevExpress.DataAccess


public MongoDBDataSource(
    string connectionName


Name Type Description
connectionName String

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


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.

// Use the created object as a data source in your application or component.
See Also