Fedarovich.Aspire.Hosting.MongoDB.ReplicaSet 13.2.1

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

MongoDB Replica Set Support for Aspire

This project provides support of MongoDB replica sets in Aspire.

It uses MongoDB horizons feature to correctly handle replica set configuration and make it available from both Aspire internal container network and host machine. The replica set correctly handles container restarts and Aspire process restarts.

This package supports both single instance replica sets and multi-instance replica sets, allowing you to choose the configuration that best suits your development and testing needs.

Both original MongoDB Server and Percona Server for MongoDB are supported, giving you flexibility in your choice of MongoDB distribution.

Installation

Install the package from nuget:

dotnet add package Fedarovich.Aspire.Hosting.MongoDB.ReplicaSet

Creating a Single Instance Replica Set

For most development and testing scenarios, a single instance replica set is sufficient. It provides the benefits of replica sets without the overhead of managing multiple instances.

Creating a single instance replica set is straightforward with this package:


// Add MongoDB server with a fixed port
var mongoServer = builder.AddMongoDB("TestMongo", 27017);

// Add database to the server
mongoServer.AddDatabase("TestMongoDB", "TestDB");

// Add replica set with the server as a member
var mongoRS = builder.AddMongoDBReplicaSet("TestMongoRS")
    .WithMember(mongoServer);

// Reference the replica set from other resources
var webApiLocal = builder.AddProject<WebApi>("WebApi-Local")
    .WithReference(mongoRs);

The created MongoDBReplicaSet resource provides the connection string and can be used as an argument of .WithReference() extension method.

You can also do it with TypeScript AppHost:


// Add MongoDB server with a fixed port
const mongoServer = await builder.addMongoDB('TestMongo', { port: 27017 });

// Add database to the server
await mongoServer.addDatabase('TestMongoDB');

// Add replica set with the server as a member
const mongoRS = await builder.addMongoDBReplicaSet('TestMongoRS')
    .withMember(mongoServer);

// Reference the replica set from other resources
const nodeLocal = await builder.addJavaScriptApp('NodeJS-Local', '../WebApi')
    .withHttpEndpoint({ targetPort: 3000 })
    .withReference(mongoRS);

Samples

See the project repository for more samples and documentation: Fedarovich.Aspire.Hosting.MongoDB.ReplicaSet

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
13.2.1 2,248 4/1/2026
13.2.0 139 3/30/2026