Regira.DAL.MongoDB 6.1.2

dotnet add package Regira.DAL.MongoDB --version 6.1.2
                    
NuGet\Install-Package Regira.DAL.MongoDB -Version 6.1.2
                    
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="Regira.DAL.MongoDB" Version="6.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Regira.DAL.MongoDB" Version="6.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Regira.DAL.MongoDB" />
                    
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 Regira.DAL.MongoDB --version 6.1.2
                    
#r "nuget: Regira.DAL.MongoDB, 6.1.2"
                    
#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 Regira.DAL.MongoDB@6.1.2
                    
#: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=Regira.DAL.MongoDB&version=6.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Regira.DAL.MongoDB&version=6.1.2
                    
Install as a Cake Tool

Regira DAL — MongoDB

Regira DAL.MongoDB provides lightweight MongoDB connectivity using the MongoDB Driver, plus backup/restore via mongodump/mongorestore.

Projects

Project Package Backend CRUD Backup / Restore
DAL.MongoDB Regira.DAL.MongoDB MongoDB via MongoDB Driver ✓ (mongodump)

Installation

<PackageReference Include="Regira.DAL.MongoDB" Version="6.*" />

MongoSettings

Property Type Description
Host string Hostname / replica set
DatabaseName string Target database
Port string Port (default 27017)
Username string? Auth username
Password string? Auth password
UseSecure (UseTls) bool TLS/SSL
var settings = new MongoSettings("localhost", "mydb");
// or parse from connection string:
settings = MongoSettings.FromConnectionString("mongodb://user:pass@host:27017/mydb");

MongoCommunicator

var settings = new MongoSettings("localhost", "mydb");
var comm = new MongoCommunicator(settings);
var names = comm.ListCollectionNames();   // IAsyncEnumerable<string>

The underlying IMongoDatabase (Database) is protected internal — it is not accessible on the communicator from consumer code, only from repository classes derived from MongoDbRepositoryBase<TEntity>.

MongoDbRepositoryBase<TEntity>

Extend this to build a repository (TEntity must be a class with a parameterless constructor). The base constructor takes the communicator, an ISerializer, id accessor delegates, and an optional collection name. Override GetFilter(), SortResult(), and PageResult() for custom queries.

public class Product
{
    public string? Id { get; set; }
    public string? Name { get; set; }
}

public class ProductRepository(MongoCommunicator comm, ISerializer serializer)
    : MongoDbRepositoryBase<Product>(
        comm,
        serializer,
        getIdFunc: p => p.Id,
        setIdAction: (p, id) => p.Id = id,
        collectionName: "products")
{
    protected override FilterDefinition<BsonDocument> GetFilter(IDictionary<string, object?>? so)
    {
        var filter = base.GetFilter(so);
        if (so?.TryGetValue("name", out var name) == true && name != null)
        {
            filter &= Builders<BsonDocument>.Filter.Eq("Name", name.ToString());
        }
        return filter;
    }
}

CRUD methods:

Task<TEntity?>             Details(object id)
Task<IEnumerable<TEntity>> List(object? searchObject = null)
Task<long>                 Count(object? searchObject = null)
Task<long>                 Save(TEntity item)     // inserted (1) or modified count
Task<long>                 Delete(TEntity item)   // deleted count

MongoBackupService / MongoRestoreService

Requires mongodump / mongorestore executables in MongoOptions.ToolsDirectory. Both services also take an IProcessHelper (e.g. ProcessHelper from Regira.System) to run those executables.

var settings = new MongoSettings("localhost", "mydb");
var options = new MongoOptions
{
    DbSettings     = settings,
    ToolsDirectory = "/usr/bin"
};
IProcessHelper processHelper = new ProcessHelper();

IMemoryFile backup = await new MongoBackupService(options, processHelper).Backup();
await new MongoRestoreService(options, processHelper).Restore(backup);

Backup/Restore contracts

Both services implement the shared contracts from Common:

public interface IDbBackupService  { Task<IMemoryFile> Backup(); }
public interface IDbRestoreService { Task Restore(IMemoryFile file); }

Overview

  1. Index — Settings, communicator, repository, and backup/restore
  2. Examples — Connect, query, and backup

License

Apache License 2.0 — this package contains no license validation and no runtime limits. See LICENSE. A few companion packages are commercially licensed with a free tier; see the licensing overview.

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 is compatible.  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
6.1.2 92 8/16/2026
6.1.1 90 8/12/2026
6.1.0 103 8/10/2026