Back to Devexpress

MongoDBQueryCollection Class

corelibraries-devexpress-dot-dataaccess-dot-mongodb-f40f9af8.md

latest4.7 KB
Original Source

MongoDBQueryCollection Class

Stores a collection of queries to a MongoDB instance.

Namespace : DevExpress.DataAccess.MongoDB

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public class MongoDBQueryCollection :
    IList,
    ICollection,
    IEnumerable,
    IQueryCollection<MongoDBQuery>,
    IList<MongoDBQuery>,
    ICollection<MongoDBQuery>,
    IEnumerable<MongoDBQuery>
vb
Public Class MongoDBQueryCollection
    Implements IList,
               ICollection,
               IEnumerable,
               IQueryCollection(Of MongoDBQuery),
               IList(Of MongoDBQuery),
               ICollection(Of MongoDBQuery),
               IEnumerable(Of MongoDBQuery)

The following members return MongoDBQueryCollection objects:

Example

The example below demonstrates how to use the MongoDBDataSource class to bind an application/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.

csharp
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.MongoDB;
// ...
// Create a MongoDBCustomConnectionParameters object and assign
// a connection string to a MongoDB instance to the object's
// ConnectionString property.
var connectionString = new MongoDBCustomConnectionParameters() {
    ConnectionString = "mongodb://localhost: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 = connectionString,
    Queries = { queryCategories, 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.
//...
vb
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.MongoDB
' ...
' Create a MongoDBCustomConnectionParameters object and assign
' a connection string to a MongoDB instance to the object's
' ConnectionString property.
Dim connectionString = New MongoDBCustomConnectionParameters() With {
    .ConnectionString = "mongodb://localhost:27017"
}

' Specify queries to database collections.
Dim queryCategories = New MongoDBQuery() With {
    .DatabaseName = "Northwind",
    .CollectionName = "Categories"
}

Dim queryProducts = New MongoDBQuery() With {
    .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.
Dim mongoDBDataSource = New MongoDBDataSource() With {
    .ConnectionParameters = connectionString
}

mongoDBDataSource.Queries.Add(queryCategories)
mongoDBDataSource.Queries.Add(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.
'...
vb
...

Inheritance

Object MongoDBQueryCollection

See Also

MongoDBQueryCollection Members

DevExpress.DataAccess.MongoDB Namespace