ApiFeatures.Mqtt.MongoDatabases 9.1.0

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

ApiFeatures.Mqtt.MongoDatabases

MongoDB persistence for the MQTT module. Isolated from ApiFeatures.Mqtt.Apis so the Mongo layer can be composed by the host and swapped without touching the domain (ApiFeatures.Mqtt.Cores) or the API surface (ApiFeatures.Mqtt.Apis).

Contents

  • Databases/MongoMqttDatabaseContext.cs — the Mongo client/database/collections, index creation, and BSON class-map registration.
  • Serializers/MqOptionsBsonSerializer.cs — polymorphic BSON serializer for MqOptions (HiveMQ / self-hosted broker options).
  • Models/Options/MongoMqttDatabaseOptions.cs — extends the shared ApiFeatures.Modules.Cores.Models.Options.ModuleMongoDatabaseOptions (Type == Mongo, broken-out connection components: Host, Port, DatabaseName, Username, Password, AuthenticationDatabase, ReplicaSet, UseTls — no single connection string), plus the MQTT-specific Collections (per-collection name overrides).
  • Models/Options/MongoMqttDatabaseCollectionOptions.cs — one nullable name override per collection (Mqtts, MqttConnections, Brokers, BrokerUsers); null/blank falls back to the agreed PascalCase default (Mqtts, MqttConnections, Brokers, BrokerUsers).
  • Services/{MqttService,MqttConnectionService,BrokerService,BrokerUserService}.cs — Mongo-backed implementations of the ApiFeatures.Mqtt.Cores.Interfaces service contracts.
  • Extensions/MqttMongoDatabaseExtensions.cs — WithMongoDatabase(this IServiceCollection, options) composition entry point.

Connection equivalence (vs. the former single ConnectionString)

The former MongoMqttDatabaseContext built its client from a single connection string (with an injected uuidRepresentation=standard hint and mongoUrl.DatabaseName ?? options.DatabaseName resolution). This project assembles the client from the broken-out ModuleMongoDatabaseOptions components instead:

  • Servers = [new MongoServerAddress(Host, Port ?? 27017)].
  • When Username is non-blank: Credential = MongoCredential.CreateCredential(AuthenticationDatabase ?? DatabaseName, Username, Password) — AuthenticationDatabase is the old connection string's authSource.
  • When ReplicaSet is non-blank: ReplicaSetName = ReplicaSet.
  • When UseTls is true: UseTls = true.
  • Database name resolution comes solely from DatabaseName; an empty/missing DatabaseName throws ArgumentException — the same guard as before, just no longer sourced from a connection string.
  • GUID serialization equivalence: the former uuidRepresentation=standard connection-string hint is not needed — the context has always set GuidSerializer(GuidRepresentation.Standard) explicitly on every entity's Guid-typed BSON class-map member (MqttEntity.Id, MqttConnectionEntity.Id/MqttId, BrokerEntity.Id, BrokerUserEntity.Id/BrokerId). Those class maps move here unchanged, so GUID serialization behaviour is identical.

Collection-name defaults

The pre-existing codebase had two different defaults for the same collections: the context's internal fallback ("mqtts", "mqttConnections", "Brokers", "BrokerUsers", used only when Collections was null) and the options class's documented defaults ("Mqtts", "MqttConnections", "Brokers", "BrokerUsers", used when a non-null Collections left a property at its default). This project resolves that inconsistency to one agreed PascalCase default per collection — MongoMqttDatabaseCollectionOptions.DefaultMqtts / DefaultMqttConnections / DefaultBrokers / DefaultBrokerUsers — matching the documented options defaults and the real demo host's explicit appsettings.Development.json values (so the running app and any consumer with an explicit Collections section are unaffected). A null or whitespace-only override falls back to the default.

Usage

using ApiFeatures.Mqtt.MongoDatabases.Extensions;
using ApiFeatures.Mqtt.MongoDatabases.Models.Options;

var mongoOptions = new MongoMqttDatabaseOptions
{
    Host = "localhost",
    Port = 27017,
    DatabaseName = "demo-mqtt",
    // Username/Password/AuthenticationDatabase/ReplicaSet/UseTls optional
    Collections = new MongoMqttDatabaseCollectionOptions
    {
        Mqtts = "Mqtts",
        MqttConnections = "MqttConnections",
        Brokers = "Brokers",
        BrokerUsers = "BrokerUsers"
    }
};

builder.Services.WithMongoDatabase(mongoOptions);

WithMongoDatabase registers MongoMqttDatabaseContext plus IMqttService, IMqttConnectionService, IBrokerService, and IBrokerUserService (all keyed ApiFeatures.Mqtt.Cores.Constants.ServiceKeys.Default, scoped). It does not register IBrokerUserPasswordHasher — the host must also call AddMqttsModule(...) (from ApiFeatures.Mqtt.Apis), which registers the hasher implementation unconditionally; BrokerUserService resolves it lazily at request time from the same container, so call order between WithMongoDatabase and AddMqttsModule does not matter.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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
9.1.0 56 10/30/2026
9.0.0 165 10/23/2026