UEntity.MongoDb 3.1.0.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package UEntity.MongoDb --version 3.1.0.9                
NuGet\Install-Package UEntity.MongoDb -Version 3.1.0.9                
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="UEntity.MongoDb" Version="3.1.0.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UEntity.MongoDb --version 3.1.0.9                
#r "nuget: UEntity.MongoDb, 3.1.0.9"                
#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 UEntity.MongoDb as a Cake Addin
#addin nuget:?package=UEntity.MongoDb&version=3.1.0.9

// Install UEntity.MongoDb as a Cake Tool
#tool nuget:?package=UEntity.MongoDb&version=3.1.0.9                

UEntity.MongoDb NuGet Package

Introduction

The UEntity.MongoDb NuGet package provides a flexible and efficient repository pattern implementation for MongoDB. This package simplifies common MongoDB operations such as querying, inserting, updating, deleting, and pagination.

Getting Started

Installation

Install the package via NuGet:

Install-Package UEntity.MongoDb

Configuration

To use the package, configure it in your Program.cs file by calling the AddUEntityMongoDb extension method.

using MongoDB.Driver;
using Microsoft.Extensions.DependencyInjection;
using UEntity.MongoDb;

var services = new ServiceCollection();
var mongoClient = new MongoClient("YourMongoDbConnectionString");
services.AddUEntityMongoDb(mongoClient);

Usage

Repository Methods

The IEntityRepositoryMongo<T> interface provides the following methods for MongoDB operations:

1. Get

Retrieves a single document based on a filter.

var repository = new EntityRepositoryMongo<MyEntity>("DatabaseName");
var result = repository.Get(x => x.Id == "12345");
2. GetAsync

Asynchronously retrieves a single document based on a filter.

var result = await repository.GetAsync(x => x.Id == "12345");
3. GetAll

Retrieves all documents matching a filter.

var results = repository.GetAll(x => x.IsActive);
4. GetAllAsync

Asynchronously retrieves all documents matching a filter.

var results = await repository.GetAllAsync(x => x.IsActive);
5. GetListPaginate

Retrieves paginated results.

var paginatedResults = repository.GetListPaginate(0, 10, filter: null, sort: null);
6. Add

Inserts a single document into the collection.

var entity = new MyEntity { Id = "12345", Name = "Test" };
repository.Add(entity);
7. AddAsync

Asynchronously inserts a single document into the collection.

await repository.AddAsync(entity);
8. Update

Updates a document based on a filter.

var updateResult = repository.Update(x => x.Id == "12345", updatedEntity);
9. Delete

Deletes a document based on a filter.

var deleteResult = repository.Delete(x => x.Id == "12345");

Advanced Topics

Sorting

Use the EntitySortModel<T> to define sorting criteria:

var sortModel = new EntitySortModel<MyEntity>
{
    Sort = x => x.Name,
    IsDescending = false
};
var results = repository.GetAll(x => x.IsActive, sortModel);

Pagination

Efficiently retrieve paginated data with filters and sorting:

var paginatedData = await repository.GetListPaginateAsync(0, 10, filter: null, sort: sortModel);

Conclusion

The UEntity.MongoDb package simplifies MongoDB operations while offering flexibility for advanced use cases. Integrate it into your projects to streamline database operations and enhance maintainability.

For additional support or contributions, refer to the repository's documentation or reach out to the maintainers.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.0.11 39 2/7/2025
3.1.0.10 28 2/6/2025
3.1.0.9 31 2/6/2025
3.1.0.8 30 2/6/2025
3.1.0.7 70 2/1/2025
3.1.0.6 40 1/29/2025
3.1.0.5 41 1/29/2025
3.1.0.4 37 1/29/2025
3.1.0.3 47 1/24/2025
3.1.0.2 49 1/24/2025
3.1.0.1 44 1/24/2025
3.1.0 43 1/24/2025