Docs Menu

FAQ

This page contains frequently asked questions and their corresponding answers.

Tip

If you can't find an answer to your problem on this page, see the Issues & Help page for next steps and more resources.

The MongoDB .NET/C# Driver is a library that exposes MongoDB functionality directly and includes a LINQ provider with projections, group operations, and flexible mapping. The driver includes features such as the following:

  • Transactions

  • Bulk operations

  • LINQ queries

  • Operations that directly modify the database

  • Aggregation operations

  • Custom mapping

The EF Core Provider allows you to use Microsoft's Entity Framework Core with MongoDB in your .NET/C# applications. The EF Core Provider supports change tracking, entity-based LINQ operations, and modeling familiar to Entity Framework Core users. The provider includes features such as the following:

  • Intelligent object tracking

  • Entity-based LINQ operations

  • Entity Framework modeling and mapping with the fluent API

  • Automatic database updates through change tracking

You can create indexes with the EF Core Provider by calling the HasIndex() method in the OnModelCreating() method of your DbContext class. To learn more about how to create indexes with the EF Core Provider, see the Indexes guide.

Because the EF Core Provider is built on top of the .NET/C# Driver, you can also manage indexes in your application by using the .NET/C# Driver directly. To use driver methods in your EF Core Provider application, call them on the MongoClient used to set up your DbContext.

The following example creates indexes on the movies collection by using .NET/C# Driver methods:

using MongoDB.Driver;
var client = new MongoClient("<connection string>");
var database = client.GetDatabase("sample_mflix");
await CreateIndexesAsync(database);
async Task CreateIndexesAsync(IMongoDatabase database)
{
var moviesIndex = new CreateIndexModel<Movie>(Builders<Movie>.IndexKeys
.Ascending(x => x.Title)
.Ascending(x => x.Genres));
await database.GetCollection<Movie>("movies")
.Indexes.CreateOneAsync(moviesIndex);
}

To learn more about creating indexes by using the driver, see the Indexes guide in the MongoDB .NET/C# Driver documentation.