Skip to main content
Published
Feb 26, 2026
7mo ago
Total Downloads
1.1M
1,124,761

Install

dotnet add package Aspire.Hosting.MongoDB --version 13.1.2
ProductVersions
.NET
net8.0

README

Aspire.Hosting.MongoDB library

Provides extension methods and resource definitions for an Aspire AppHost to configure a MongoDB resource.

Getting started

Install the package

In your AppHost project, install the Aspire MongoDB Hosting library with NuGet:

dotnet add package Aspire.Hosting.MongoDB

Usage example

Then, in the AppHost.cs file of AppHost, add a MongoDB resource and consume the connection using the following methods:

var db = builder.AddMongoDB("mongodb").AddDatabase("mydb");

var myService = builder.AddProject<Projects.MyService>()
                       .WithReference(db);

Connection Properties

When you reference a MongoDB resource using WithReference, the following connection properties are made available to the consuming project:

MongoDB server

The MongoDB server resource exposes the following connection properties:

Property Name Description
Host The hostname or IP address of the MongoDB server
Port The port number the MongoDB server is listening on
Username The username for authentication
Password The password for authentication (available when a password parameter is configured)
AuthenticationDatabase The authentication database (available when a password parameter is configured)
AuthenticationMechanism The authentication mechanism (available when a password parameter is configured)
Uri The connection URI, with the format mongodb://{Username}:{Password}@{Host}:{Port}/?authSource={AuthenticationDatabase}&authMechanism={AuthenticationMechanism}

MongoDB database

The MongoDB database resource combines the server properties above and adds the following connection property:

Property Name Description
DatabaseName The MongoDB database name

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called db1 becomes DB1_URI.

Additional documentation

Feedback & contributing

https://github.com/dotnet/aspire

Changes from Previous Version

No structural changes between v13.1.1 and v13.1.2.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.The published metadata declares 28 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.