Getting Started With dotConnect for MongoDB

Below are some resources to help you maximize your experience with dotConnect for MongoDB.

dotConnect for MongoDB is an ADO.NET data provider with ORM support that enables .NET applications to connect to MongoDB and work with its data using SQL.

  • EF Core, Dapper, NHibernate ORM support
  • SQL queries and native MongoDB commands
  • Broad compatibility with various .NET platforms and versions
  • Full compliance with ADO.NET
  • Integration with Visual Studio

Code examples

using Devart.Data.MongoDB;

class Program
{
  static void Main()
  {
    using MongoDBConnection conn = new(
      "Host=localhost;" +
      "Port=27017;" +
      "User Id=your_username;" +
      "Password=your_password;" +
      "Database=your_database;" +
      "License Key=your_license_key");
    conn.Open();
  }
}
PM> Install-Package Devart.Data.MongoDB
using Devart.Data.MongoDB;
using System;

class Program
{
  static void Main()
  {
    using MongoDBConnection conn = new(
      "Host=localhost;" +
      "Port=27017;" +
      "User Id=your_username;" +
      "Password=your_password;" +
      "Database=your_database;" +
      "License Key=your_license_key");
    conn.Open();

    using MongoDBCommand cmd = new("SELECT id, name FROM orders", conn);
    using MongoDBDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
      Console.WriteLine(reader["name"]);
    }
  }
}
PM> Install-Package Devart.Data.MongoDB
using Devart.Data.MongoDB;
using System;

class Program
{
  static void Main()
  {
    using MongoDBConnection conn = new(
      "Host=localhost;" +
      "Port=27017;" +
      "User Id=your_username;" +
      "Password=your_password;" +
      "Database=your_database;" +
      "License Key=your_license_key");
    conn.Open();

    using MongoDBCommand cmd = new("SELECT id, name FROM orders WHERE id = :id", conn);
    cmd.Parameters.Add("id", 1);
    using MongoDBDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
      Console.WriteLine(reader["name"]);
    }
  }
}
PM> Install-Package Devart.Data.MongoDB
using Devart.Data.MongoDB;
using System.Data;

class Program
{
  static void Main()
  {
    using MongoDBConnection conn = new(
      "Host=localhost;" +
      "Port=27017;" +
      "User Id=your_username;" +
      "Password=your_password;" +
      "Database=your_database;" +
      "License Key=your_license_key");
    conn.Open();

    using MongoDBDataAdapter adapter = new("SELECT id, name FROM orders", conn);
    DataTable table = new();
    adapter.Fill(table);
  }
}
PM> Install-Package Devart.Data.MongoDB
using Devart.Data.MongoDB;
using Microsoft.EntityFrameworkCore;
using System.Linq;

class Order
{
  public string Id { get; set; }
  public string Name { get; set; }
  public double Amount { get; set; }
}

class AppDbContext : DbContext
{
  public DbSet<Order> Orders { get; set; }

  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
    optionsBuilder.UseMongoDB(
      "Host=localhost;" +
      "Port=27017;" +
      "User Id=your_username;" +
      "Password=your_password;" +
      "Database=your_database;" +
      "License Key=your_license_key",
      o => o.UseCamelCaseFieldNames());
  }

  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
    modelBuilder.Entity<Order>().ToTable("orders");
  }
}

class Program
{
  static void Main()
  {
    using AppDbContext db = new();
    var orders = db.Orders.Take(10).ToList();
  }
}
PM> Install-Package Devart.Data.MongoDB.EFCore
using Devart.Data.MongoDB;
using System;

class Program
{
  static void Main()
  {
    using MongoDBConnection conn = new(
      "Host=localhost;" +
      "Port=27017;" +
      "User Id=your_username;" +
      "Password=your_password;" +
      "Database=your_database;" +
      "License Key=your_license_key");
    conn.Open();

    MongoDBLoader loader = new("orders", conn);
    loader.Open();
    for (int i = 1; i <= 100; i++)
    {
      loader.SetValue("id", i);
      loader.SetValue("name", "Order " + i);
      loader.SetValue("amount", i * 10.5);
      loader.NextRow();
    }
    loader.Close();
  }
}
PM> Install-Package Devart.Data.MongoDB

Documentation

Licensing
A detailed technical reference on embedding license information - a required resource for applications built with dotConnect for MongoDB.
Deployment
A guide to deploying applications built with dotConnect for MongoDB, including the required runtime assemblies.
DataAdapter features
A guide to using the MongoDBDataAdapter class for interacting with MongoDB data in a disconnected architecture.
MongoDBLoader
A reference for the MongoDBLoader class that inserts data into MongoDB collections in bulk.

dotConnect Universal

Get universal access to data from a variety of sources, including SQL Server, Oracle, PostgreSQL, MySQL, SQLite, DB2, InterBase, Microsoft Access, and Firebird. Other servers can be accessed through their ADO.NET, OLE DB and ODBC providers.

FAQ

What is the trial period for dotConnect for MongoDB?
dotConnect for MongoDB offers a fully functional 30-day trial. During this period, you can use and evaluate all features without limitations. After the trial ends, you can purchase a license to keep using the product.
Can I use dotConnect for MongoDB in Visual Studio Code, JetBrains Rider, or other IDEs?

Yes. Add the Devart.Data.MongoDB NuGet package (and Devart.Data.MongoDB.EFCore for Entity Framework Core) to your project and specify the license key.

Design-time features, such as Server Explorer integration and Toolbox components, are available only in Visual Studio.

Where should I apply my License Key?

Specify the key in the License Key connection string parameter. Alternatively, call the static MongoDBConnection.LoadLicenseKey method before opening the first connection.

Do end users of my application need a Devart license, or do I have to pay additional fees for deploying my software?

End users of your application do not need a Devart license. Any dotConnect license allows deploying your application to an unlimited number of desktops, workstations, and non-production servers within your company. To deploy the application to a production server, you need a Server license for each server. To distribute the application to third parties, you need the OEM license.

According to the EULA, you're allowed to redistribute the following runtime assemblies with your application:

  • Devart.Data.MongoDB.dll
  • Devart.Data.dll
  • Devart.Data.MongoDB.EFCore.dll (for Entity Framework Core applications)
  • libmongoc-1.0.dll, libbson-1.0.dll, sqlite3.dll, and vcruntime140.dll (native libraries for the platform of your application, from the Native\win-x86 or Native\win-x64 folder of the installation)

If you reference the provider via NuGet packages, these assemblies are copied to the output folder automatically.

There's no need for a full installation on the target machine, you can also use the "Minimal installation" option provided by the setup.

No other components of dotConnect may be distributed.

How can I update dotConnect for MongoDB to a new version?

Close all running IDEs and help collections, then run the installation package of the newer version. You will be prompted to uninstall the previous version. Agree, and then proceed to installing the newer build.

If you use NuGet packages, update the Devart.Data.MongoDB package (and Devart.Data.MongoDB.EFCore, if used) to the new version.

How can I completely remove all previous versions of a product?
  1. Go to Settings > Apps > Installed apps and uninstall:
    • All dotConnect providers
    • Entity Developer
    • LinqConnect
  2. Manually delete any leftover files from the following locations (if they exist):

    GAC folders:

    • C:\Windows\assembly\GAC_MSIL
    • C:\Windows\Microsoft.NET\assembly\GAC_MSIL

    Program files and extensions:

    • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Devart
    • C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Devart
    • C:\Program Files (x86)\Devart
    • C:\Program Files\Devart
    • C:\Program Files (x86)\Common Files\Devart
    • C:\Program Files\Common Files\Devart

    Program data folders:

    • C:\ProgramData\Devart\dotConnect
    • C:\ProgramData\Devart\Entity Developer

Removing these ensures a clean system and prevents conflicts during future installations.

dotConnect for MongoDB

Get an ORM-enabled data provider for MongoDB and build .NET applications that work with MongoDB data quickly and easily.

Try the 30-day trial of the full product. No limits. No card required. Start free trial