Skip to main content
All docs
V25.1
  • MongoDBConnectionParameters(String, Boolean, Int32, MongoDBAuthenticationInfo) Constructor

    Initializes a new instance of the MongoDBConnectionParameters class.

    Namespace: DevExpress.DataAccess.ConnectionParameters

    Assembly: DevExpress.DataAccess.v25.1.dll

    NuGet Package: DevExpress.DataAccess

    Declaration

    public MongoDBConnectionParameters(
        string hostName,
        bool isSRV,
        int port = 0,
        MongoDBAuthenticationInfo info = null
    )

    Parameters

    Name Type Description
    hostName String

    The hostname of a MongoDB instance.

    isSRV Boolean

    true if the Hostname property contains an SRV record; otherwise, false.

    Optional Parameters

    Name Type Default Description
    port Int32 0

    The port on which a MongoDB instance listens.

    info MongoDBAuthenticationInfo null

    Authentication information for a MongoDB instance.

    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 MongoDBConnectionParameters class to specify connection parameters to the MongoDB instance, the MongoDBPasswordAuthenticationInfo class to specify connection credentials, and the MongoDBQuery class to create data queries to the Categories and Products collections of the Northwind database.

    using DevExpress.DataAccess.ConnectionParameters;
    using DevExpress.DataAccess.MongoDB;
    // ...
    var MongoDBPasswordAuthInfo = new MongoDBPasswordAuthenticationInfo(
        username: "name",
        password: "password",
        authenticationDatabase: "admin"
    );
    
    // Create a MongoDBConnectionParameters object and
    // specify connection parameters to a MongoDB instance.
    var connectionParameters = new MongoDBConnectionParameters(
        hostName: "localhost",
        isSRV: false,
        port: 27017,
        info: MongoDBPasswordAuthInfo
    );
    
    // 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
    // parameters 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.
    mongoDBDataSource.Fill();
    
    // Use the created object as a data source in your application or component.
    // ...
    
    See Also