ArturRios.Data.MongoDb 1.0.3

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

ArturRios.Data.MongoDb

NuGet Docs License: MIT

A MongoDB document store for the ArturRios.Data toolkit — the same enveloped repository style as the relational packages, over the official MongoDB .NET driver.

Every operation returns a DataOutput / ProcessOutput envelope, so infrastructure failures — including optimistic-concurrency conflicts — surface as errors on the result instead of unhandled exceptions.

This package is standalone: it does not need ArturRios.Data.Relational.Core.

Installation

dotnet add package ArturRios.Data.MongoDb

Requires .NET 10.0 or later.

Quick start

1. Define a document:

using ArturRios.Data.MongoDb;

[MongoCollection("products")]          // optional — defaults to the type name
public class Product : Document        // or : VersionedDocument for optimistic concurrency
{
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
}

Document supplies a string Id mapped to the BSON _id as an ObjectId.

2. Configure (appsettings.json, default section "ArturRios.Data.MongoDb"):

{
  "ArturRios.Data.MongoDb": {
    "ConnectionString": "mongodb://localhost:27017",
    "DatabaseName": "mydb"
  }
}

3. Register (Program.cs):

using ArturRios.Data.MongoDb.DependencyInjection;

builder.Services.AddMongoData(builder.Configuration);

There is also an AddMongoData(MongoOptions) overload if you'd rather build the options yourself.

4. Inject and use:

using ArturRios.Data.MongoDb.Interfaces;
using ArturRios.Data.MongoDb.Transactions;
using ArturRios.Output;

public class ProductService(IAsyncDocumentRepository<Product> repo, IAsyncMongoUnitOfWork unitOfWork)
{
    public async Task<IEnumerable<Product>> CheapAsync(decimal max, CancellationToken ct = default)
    {
        DataOutput<IEnumerable<Product>> result = await repo.FindAsync(p => p.Price <= max, ct);
        return result.Success ? result.Data : [];
    }

    public Task<DataOutput<string>> CreateTwoAtomicallyAsync(Product a, Product b) =>
        unitOfWork.ExecuteInTransactionAsync(async () =>
        {
            var first = await repo.CreateAsync(a);
            await repo.CreateAsync(b);
            return first.Data;
        });
}

What's registered

Service Implementation Lifetime
IDocumentReadOnlyRepository<T> / IDocumentRepository<T> MongoDocumentRepository<T> Scoped
IAsyncDocumentReadOnlyRepository<T> / IAsyncDocumentRepository<T> MongoDocumentRepository<T> Scoped
IMongoUnitOfWork / IAsyncMongoUnitOfWork MongoUnitOfWork Scoped
IMongoClient driver client Singleton

Repository surface

Reads: GetAll(), GetById(string), Find(predicate) (a server-side filter), and Query() — a deferred IQueryable<T> escape hatch. Writes: Create, CreateRange, Update, UpdateRange, Delete, DeleteRange — each with an …Async counterpart taking a CancellationToken.

Query() is not transaction-aware. The driver's LINQ provider does not use the session, so a Query() inside a unit of work will not see writes made earlier in that same transaction. Use GetAll/Find for transaction-aware reads.

Optimistic concurrency

Derive from VersionedDocument to opt in. It adds a monotonic Version that is incremented on each update and checked on write, so a concurrent modification fails the update and returns an error on the envelope rather than silently overwriting.

Transactions

IMongoUnitOfWork / IAsyncMongoUnitOfWork expose ExecuteInTransaction(work), which runs the work in a driver session. Multi-document transactions require a replica set — they are not available on a standalone mongod.

Documentation

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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
1.0.3 82 7/24/2026
1.0.2 90 7/23/2026
1.0.1 89 7/15/2026
1.0.0 94 7/15/2026