Skip to main content
All docs

MongoDBDataSourceBase.Fill() Method

Executes queries and loads data from a MongoDB instance.

Namespace: DevExpress.DataAccess.MongoDB

Assembly: DevExpress.DataAccess.v22.2.dll

NuGet Package: DevExpress.DataAccess


public void Fill()


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.


The example below demonstrates how to use the MongoDBDataSource class to bind an application/component to a MongoDB instance. The example uses the MongoDBConnectionParameters to specify connection parameters to the MongoDB instance and the MongoDBQuery class to specify data queries to the Categories and Products collections of the Northwind database.

using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.MongoDB;
// ...
// Create a MongoDBConnectionParameters object and
// specify connection parameters to a MongoDB instance.
var connectionParameters = new MongoDBConnectionParameters(
    hostName: "localhost",
    isSRV: false,
    port: 27017

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

var queryProducts = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Products",

// 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 = { queryCategories, 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