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.Queries Property

Stores a collection of queries to a MongoDB instance.

Namespace: DevExpress.DataAccess.MongoDB

Assembly: DevExpress.DataAccess.v21.1.dll

Declaration

public MongoDBQueryCollection Queries { get; }

Property Value

Type Description
MongoDBQueryCollection

A collection of queries to a MongoDB instance.

Remarks

Use the Queries property to specify data queries to database collections of a MongoDB instance. Initialize a MongoDBQuery object and assign the name of a database and the name of a database collection to the object’s DatabaseName and CollectionName properties. Use the object’s FilterString property to specify a filter condition for items of database collections. Add the created query to the Queries collection.

The names of all queries within the Queries collection should be unique. A string stored in a query’s CollectionName property is the default name for this query. To create several queries to the same MongoDB database collection, use the Alias property to specify different names for these queries.

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.

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

// Specify queries to database collections.
var queryParamLowPrice = new QueryParameter() {
    Name = "LowPrice",
    Type = typeof(int),
    Value = 10
};

var queryLowPriceProducts = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Products",
    Alias = "LowPriceProducts",
    FilterString = "[UnitPrice] <= ?LowPrice",
    Parameters = { queryParamLowPrice }
};

var queryParamHighPrice = new QueryParameter() {
    Name = "HighPrice",
    Type = typeof(int),
    Value = 40
};

var queryHighPriceProducts = new MongoDBQuery() {
    DatabaseName = "Northwind",
    CollectionName = "Products",
    Alias = "HighPriceProducts",
    FilterString = "[UnitPrice] >= ?HighPrice",
    Parameters = { queryParamHighPrice }
};

// 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 = { queryLowPriceProducts, queryHighPriceProducts }
};

// 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