Skip to main content
All docs
V24.2

MongoDBDataSourceBase.Fill(IEnumerable<IParameter>, String[]) Method

Executes the specified queries and loads data from a MongoDB instance.

Namespace: DevExpress.DataAccess.MongoDB

Assembly: DevExpress.DataAccess.v24.2.dll

Declaration

public void Fill(
    IEnumerable<IParameter> sourceParameters,
    string[] queriesToFill
)

Parameters

Name Type Description
sourceParameters IEnumerable<IParameter>

A collection of parameters. You can reference these parameters in a query’s filter string property.

queriesToFill String[]

An array of query names. The queries with these names are executed after the Fill method is called.

Remarks

A MongoDB data source stores a collection of queries to database collections of a MongoDB instance. Call the Fill method to execute these queries and load data from the MongoDB instance to the data source. You can also call the FillAsync() method to load data asynchronously.

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 MongoDBCustomConnectionParameters class to specify a connection string to the MongoDB instance and the MongoDBQuery class to specify data queries to the Categories and Products collections of the Northwind database. The example shows how to use the Fill(IEnumerable<IParameter>, String[]) method to execute individual queries and reference external parameters in the queries’ FilterString property.

using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.MongoDB;
using DevExpress.DataAccess;
using DevExpress.DataAccess.ObjectBinding;
// ...
// Create a MongoDBCustomConnectionParameters object and assign
// a connection string to a MongoDB instance to the object's
// ConnectionString property.
var connectionParameters = new MongoDBCustomConnectionParameters() {
    ConnectionString = "mongodb://localhost:27017"
};

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

var paramPrice = new QueryParameter() {
    Name = "price",
    Type = typeof(Expression),
    Value = new Expression("?priceExternal")
};

var queryProducts = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Products",
    FilterString = "[UnitPrice] >= ?price",
    Parameters = { paramPrice }
};

// Create a MongoDBDataSource object. Assign the created connection
// string to the object's ConnectionParameters property. Add the
// queries to the object's Queries collection.
var mongoDBDataSource = new MongoDBDataSource() {
    ConnectionParameters = connectionParameters,
    Queries = { queryProducts, queryCategories },
};

// Create a parameter that you want to reference in the queries' filter string.
var paramPriceExternal = new Parameter() {
    Name = "priceExternal",
    Type = typeof(int),
    Value = 50
};

// Specify an array of query names. The queries with these name are executed
// after the Fill method is called.
var queriesToFill = new[] { "Products" };

// Specify an array of parameters that you reference in the queries.
var parameters = new[] { paramPriceExternal };

// Call the Fill method of the MongoDBDataSource object to execute the queries
// and load data from the MongoDB instance. Pass the array of parameters and
// the array of query names to this method.
mongoDBDataSource.Fill(parameters, queriesToFill);

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