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
<PackageReference Include="Regira.DAL.MongoDB" Version="6.1.2" />
<PackageVersion Include="Regira.DAL.MongoDB" Version="6.1.2" />
<PackageReference Include="Regira.DAL.MongoDB" />
paket add Regira.DAL.MongoDB --version 6.1.2
#r "nuget: Regira.DAL.MongoDB, 6.1.2"
#:package Regira.DAL.MongoDB@6.1.2
#addin nuget:?package=Regira.DAL.MongoDB&version=6.1.2
#tool nuget:?package=Regira.DAL.MongoDB&version=6.1.2
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
- Index — Settings, communicator, repository, and backup/restore
- 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 | Versions 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. |
-
net10.0
- MongoDB.Driver (>= 3.11.0)
- Regira.Common (>= 6.1.2)
- Regira.System (>= 6.1.2)
-
net8.0
- MongoDB.Driver (>= 3.11.0)
- Regira.Common (>= 6.1.2)
- Regira.System (>= 6.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.