MongoDbCore 1.4.1

dotnet add package MongoDbCore --version 1.4.1
                    
NuGet\Install-Package MongoDbCore -Version 1.4.1
                    
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="MongoDbCore" Version="1.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MongoDbCore" Version="1.4.1" />
                    
Directory.Packages.props
<PackageReference Include="MongoDbCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MongoDbCore --version 1.4.1
                    
#r "nuget: MongoDbCore, 1.4.1"
                    
#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.
#:package MongoDbCore@1.4.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MongoDbCore&version=1.4.1
                    
Install as a Cake Addin
#tool nuget:?package=MongoDbCore&version=1.4.1
                    
Install as a Cake Tool

MongoDbCore

Latest stable version 1.4.0

https://www.nuget.org/packages/MongoDbCore/

MongoDbCore is a lightweight micro-ORM for .NET designed to simplify interactions with MongoDB. It provides a straightforward API for performing common database operations, enabling developers to build applications quickly and efficiently.

Key Features

  • Easy Setup: Simple configuration to get started with MongoDB.
  • CRUD Operations: Supports Create, Read, Update, and Delete operations seamlessly.
  • Asynchronous Support: Perform database operations asynchronously for better performance.
  • Performance Optimizations: Designed for efficient use of memory and speed.

Installation

To install MongoDbCore, add it to your project using NuGet:

dotnet add package MongoDbCore

Getting Started

Configuration

To configure MongoDbCore, follow these steps:

  1. Set Up Your MongoDB Connection: Define your MongoDB connection string in your application settings.
"MongoDB": {
    "Connection": "mongodb://localhost:27017",
    "Database": "database_name",
    "MaxConnectionPoolSize": 100 //default
}
  1. Initialize MongoDbCore: Configure the MongoDbCore context in your Program.cs:
// Setup the application and services
builder.Services.AddMongoDbContext<AppDbContext>(builder.Configuration
                                                        .GetSection("MongoDB")
                                                        .Get<MongoDbCoreOptions>()!);

Create TodoEntity based on BaseEntity

Create a class that inherits from MongoDbContext to define your database context:

public class Todo : BaseEntity
{
    public string Task { get; set; } = string.Empty;
}

Setting Up the Database Context

Create a class that inherits from MongoDbContext to define your database context:

public class AppDbContext(MongoDbCoreOptions options) : MongoDbContext(options)
{
    public Collection<Todo> Todos { get; set; } = null!;

    protected override async Task OnInitializedAsync()
    {
        // Initialize data if necessary
    }
}

Basic CRUD Operations

MongoDbCore simplifies CRUD operations. Here's how you can use it:

Inject AppDbContext in your service class:
public class TodoService(AppDbContext dbContext)
{ }
Create

To create a new entity:

Todo newTodo = new();
dbContext.Todos.Add(newTodo);
Read

To retrieve an entity:

var todos = dbContext.Todos.ToList();
Update

To update an existing entity:

var updateTodo = dbContext.Todos.FirstOrDefault();
dbContext.Todos.Update(updateTodo);
Delete

To delete an entity:

var updateTodo = dbContext.Todos.FirstOrDefault();
dbContext.Todos.Delete(updateTodo);

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please read the CONTRIBUTING guide for details on how to contribute to this project.

Product Compatible and additional computed target framework versions.
.NET 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.4.1 68 1/9/2025
1.4.0 47 1/9/2025
1.3.0 104 10/8/2024
1.2.0 75 8/5/2024
1.1.0-alpha 78 7/24/2024
1.0.9-alpha 79 7/19/2024
1.0.8-alpha 67 7/18/2024
1.0.7-alpha 75 7/16/2024
1.0.6-alpha 64 7/16/2024
1.0.5-alpha 70 7/16/2024
1.0.4-alpha 65 7/12/2024
1.0.3-alpha 71 7/11/2024
1.0.2-alpha 57 7/10/2024
1.0.1 84 8/2/2024
1.0.1-alpha 65 7/9/2024
1.0.0 78 8/1/2024
1.0.0-alpha 73 7/2/2024

SelfCached Collection added for best time read perfomance