Defra.Livestock.Sdk.Storage.Mongo
0.1.0-LREG-999-alpha.4.1
Prefix Reserved
dotnet add package Defra.Livestock.Sdk.Storage.Mongo --version 0.1.0-LREG-999-alpha.4.1
NuGet\Install-Package Defra.Livestock.Sdk.Storage.Mongo -Version 0.1.0-LREG-999-alpha.4.1
<PackageReference Include="Defra.Livestock.Sdk.Storage.Mongo" Version="0.1.0-LREG-999-alpha.4.1" />
<PackageVersion Include="Defra.Livestock.Sdk.Storage.Mongo" Version="0.1.0-LREG-999-alpha.4.1" />
<PackageReference Include="Defra.Livestock.Sdk.Storage.Mongo" />
paket add Defra.Livestock.Sdk.Storage.Mongo --version 0.1.0-LREG-999-alpha.4.1
#r "nuget: Defra.Livestock.Sdk.Storage.Mongo, 0.1.0-LREG-999-alpha.4.1"
#:package Defra.Livestock.Sdk.Storage.Mongo@0.1.0-LREG-999-alpha.4.1
#addin nuget:?package=Defra.Livestock.Sdk.Storage.Mongo&version=0.1.0-LREG-999-alpha.4.1&prerelease
#tool nuget:?package=Defra.Livestock.Sdk.Storage.Mongo&version=0.1.0-LREG-999-alpha.4.1&prerelease
Defra.Livestock.Sdk.Storage.Mongo
MongoDB set-up for Livestock Information Service (LIS) .NET services: a client factory for the configured database, camel-case BSON conventions, and AWS IAM authentication support.
Part of lis-sdk-nuget-storage.
Installation
dotnet add package Defra.Livestock.Sdk.Storage.Mongo
This package does not depend on the other storage packages. It targets net10.0.
Usage
using Defra.Livestock.Sdk.Storage.Mongo;
builder.Services.AddMongoDatabase(builder.Configuration);
AddMongoDatabase reads the Mongo section described under Configuration
and:
- registers camel-case element names for all BSON-serialised types
- registers the MongoDB driver's AWS authentication extension
- binds and validates the settings, checked at start-up
- registers
IMongoDbClientFactoryas a singleton, which owns oneMongoClientand disposes it when the container is disposed
public class AnimalRepository(IMongoDbClientFactory factory)
{
private readonly IMongoCollection<Animal> animals = factory.GetCollection<Animal>("animals");
public Task<Animal?> FindAsync(Guid id) =>
animals.Find(a => a.Id == id).FirstOrDefaultAsync();
}
Creating the factory does not connect to the server. The driver connects on first use.
Configuration
{
"Mongo": {
"DatabaseUri": "mongodb://localhost:27017",
"DatabaseName": "my-db"
}
}
| Key | Default | Meaning |
|---|---|---|
Mongo:DatabaseUri |
none (required) | MongoDB connection string |
Mongo:DatabaseName |
none (required) | Database that GetDatabase and GetCollection use |
If either is missing, start-up fails with OptionsValidationException. To use AWS IAM
authentication, put authMechanism=MONGODB-AWS in the connection string. The driver then takes
credentials from the default AWS credentials chain.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.15)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.15)
- MongoDB.Driver (>= 3.14.1)
- MongoDB.Driver.Authentication.AWS (>= 3.14.1)
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 |
|---|---|---|
| 0.1.0-LREG-999-alpha.4.1 | 58 | 11/26/2026 |