MongoDB.Abstracts 6.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MongoDB.Abstracts --version 6.0.0                
NuGet\Install-Package MongoDB.Abstracts -Version 6.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MongoDB.Abstracts" Version="6.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoDB.Abstracts --version 6.0.0                
#r "nuget: MongoDB.Abstracts, 6.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MongoDB.Abstracts as a Cake Addin
#addin nuget:?package=MongoDB.Abstracts&version=6.0.0

// Install MongoDB.Abstracts as a Cake Tool
#tool nuget:?package=MongoDB.Abstracts&version=6.0.0                

MongoDB.Abstracts

Overview

The MongoDB Abstracts library defines abstract base classes for repository pattern.

Build status

NuGet Version

Coverage Status

Download

The MongoDB.Abstracts library is available on nuget.org via package name MongoDB.Abstracts.

To install MongoDB.Abstracts, run the following command in the Package Manager Console

PM> Install-Package MongoDB.Abstracts

More information about NuGet package available at https://nuget.org/packages/MongoDB.Abstracts

Features

  • interface for generic MongoDB queries; IMongoQuery<TEntity, TKey>
  • interface for generic MongoDB repository; IMongoRepository<TEntity, TKey>
  • base class for generic MongoDB queries; MongoQuery<TEntity, TKey>
  • base class for generic MongoDB repository; MongoRepository<TEntity, TKey>
  • interface for generic MongoDB entity; IMongoEntity
  • base class for generic MongoDB entity; MongoEntity
  • interface for generic MongoDB entity repository; IMongoEntityRepository<TEntity>
  • base class for generic MongoDB entity repository; MongoEntityRepostiory<TEntity>

Configuration

Register with dependency injection

services.AddMongoDB("mongodb://localhost:27017/UnitTesting");

Register using a connection name from the appsettings.json

services.AddMongoDB("UnitTesting");
{
  "ConnectionStrings": {
    "UnitTesting": "mongodb://localhost:27017/UnitTesting"
  }
}

Usage

Find an entity by key

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

// find by key
var role = await roleRepo.FindAsync("67a0dc52fa5ebe49f293a374");

Find one entity with query

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

// find one by query expression
var role = await roleRepo.FindOneAsync(r => r.Name.StartsWith("Admin"))

Find many with query

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

// find one by query expression
var roles = await roleRepo.FindAllAsync(r => r.Name.StartsWith("Admin"))

Use IQueryable

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

// Use IQueryable
var roles = roleRepo.All()
    .Where(r => r.IsActive)
    .ToList();

Insert entity

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

var role = new Role { Name = "CreateReadRole" };

var createdRole = await roleRepo.InsertAsync(role);

Update entity

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

// find by key
var role = await roleRepo.FindAsync("67a0dc52fa5ebe49f293a374");

// make changes
role.Name = "UpdateRole";

var updateRole = await roleRepo.UpdateAsync(role);

Delete entity by key

// dependency inject
var roleRepo = Services.GetRequiredService<IMongoEntityRepository<Role>>();

// items deleted
var count = await roleRepo.DeleteAsync("67a0dc52fa5ebe49f293a374");
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MongoDB.Abstracts:

Package Downloads
MediatR.CommandQuery.MongoDB

CQRS framework based on MediatR

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.3.0 132 2/4/2025
6.2.0 70 2/4/2025
6.1.0 76 2/3/2025
6.0.0 71 2/3/2025
5.7.1 678 7/26/2024
5.7.0 453 5/10/2024
5.6.1 715 7/28/2023
5.5.269 1,010 12/28/2022
5.5.219 931 4/23/2022
5.5.216 660 3/21/2022
5.5.191 770 12/22/2021
5.5.172 1,159 10/29/2021
5.0.0.166 371 10/21/2021
5.0.0.128 357 6/5/2021
4.0.0.102 442 2/15/2021
4.0.0.83 499 10/26/2020
4.0.0.80 514 10/17/2020
3.0.0.79 525 10/17/2020
3.0.0.56 663 5/9/2020
3.0.0.36 781 3/16/2020
2.0.0.10 784 4/23/2019
2.0.0.8 1,008 4/27/2017
2.0.0.7 978 4/4/2017
1.0.0.5 1,067 5/4/2016
1.0.0.3 1,028 4/30/2016
1.0.0.2 1,245 4/21/2016