Skip to content
DocsTry Aspire
DocsTry

MongoDBBuilderExtensions Methods

ClassMethods9 members
Provides extension methods for adding MongoDB resources to an Hosting.IDistributedApplicationBuilder.
AddDatabase(IResourceBuilder<MongoDBServerResource>, string, string?)Section titled AddDatabase(IResourceBuilder<MongoDBServerResource>, string, string?)extensionIResourceBuilder<MongoDBDatabaseResource>
Adds a MongoDB database to the application model.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBDatabaseResource> AddDatabase(
this IResourceBuilder<MongoDBServerResource> builder,
string name,
string? databaseName = null)
{
// ...
}
}
builderIResourceBuilder<MongoDBServerResource>The MongoDB server resource builder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
databaseNamestring?optionalThe name of the database. If not provided, this defaults to the same value as name.
IResourceBuilder<MongoDBDatabaseResource>A reference to the ApplicationModel.IResourceBuilder`1.
AddMongoDB(IDistributedApplicationBuilder, string, int?)Section titled AddMongoDB(IDistributedApplicationBuilder, string, int?)extensionIResourceBuilder<MongoDBServerResource>
Adds a MongoDB resource to the application model. A container is used for local development.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBServerResource> AddMongoDB(
this IDistributedApplicationBuilder builder,
string name,
int? port)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
portint?The host port for MongoDB.
IResourceBuilder<MongoDBServerResource>A reference to the ApplicationModel.IResourceBuilder`1.

This version of the package defaults to the tag of the container image.

This overload is not available in polyglot app hosts. Use MongoDBBuilderExtensions.AddMongoDB instead.

AddMongoDB(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)Section titled AddMongoDB(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<MongoDBServerResource>
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBServerResource> AddMongoDB(
this IDistributedApplicationBuilder builder,
string name,
int? port = null,
IResourceBuilder<ParameterResource>? userName = null,
IResourceBuilder<ParameterResource>? password = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
portint?optionalThe host port for MongoDB.
userNameIResourceBuilder<ParameterResource>optionalA parameter that contains the MongoDb server user name, or null to use a default value.
passwordIResourceBuilder<ParameterResource>optionalA parameter that contains the MongoDb server password, or null to use a generated password.
IResourceBuilder<MongoDBServerResource>A reference to the ApplicationModel.IResourceBuilder`1.
WithDataBindMount(IResourceBuilder<MongoDBServerResource>, string, bool)Section titled WithDataBindMount(IResourceBuilder<MongoDBServerResource>, string, bool)extensionIResourceBuilder<MongoDBServerResource>
Adds a bind mount for the data folder to a MongoDB container resource.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBServerResource> WithDataBindMount(
this IResourceBuilder<MongoDBServerResource> builder,
string source,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<MongoDBServerResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
isReadOnlybooloptionalA flag that indicates if this is a read-only mount.
IResourceBuilder<MongoDBServerResource>The ApplicationModel.IResourceBuilder`1.
WithDataVolume(IResourceBuilder<MongoDBServerResource>, string?, bool)Section titled WithDataVolume(IResourceBuilder<MongoDBServerResource>, string?, bool)extensionIResourceBuilder<MongoDBServerResource>
Adds a named volume for the data folder to a MongoDB container resource.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBServerResource> WithDataVolume(
this IResourceBuilder<MongoDBServerResource> builder,
string? name = null,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<MongoDBServerResource>The resource builder.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnlybooloptionalA flag that indicates if this is a read-only volume.
IResourceBuilder<MongoDBServerResource>The ApplicationModel.IResourceBuilder`1.
WithHostPort(IResourceBuilder<MongoExpressContainerResource>, int?)Section titled WithHostPort(IResourceBuilder<MongoExpressContainerResource>, int?)extensionIResourceBuilder<MongoExpressContainerResource>
Configures the host port that the Mongo Express resource is exposed on instead of using randomly assigned port.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoExpressContainerResource> WithHostPort(
this IResourceBuilder<MongoExpressContainerResource> builder,
int? port)
{
// ...
}
}
builderIResourceBuilder<MongoExpressContainerResource>The resource builder for Mongo Express.
portint?The port to bind on the host. If null is used random port will be assigned.
IResourceBuilder<MongoExpressContainerResource>A reference to the ApplicationModel.IResourceBuilder`1.
WithInitBindMount(IResourceBuilder<MongoDBServerResource>, string, bool)Section titled WithInitBindMount(IResourceBuilder<MongoDBServerResource>, string, bool)extensionIResourceBuilder<MongoDBServerResource>
Adds a bind mount for the init folder to a MongoDB container resource.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBServerResource> WithInitBindMount(
this IResourceBuilder<MongoDBServerResource> builder,
string source,
bool isReadOnly = true)
{
// ...
}
}
builderIResourceBuilder<MongoDBServerResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
isReadOnlybooloptionalA flag that indicates if this is a read-only mount.
IResourceBuilder<MongoDBServerResource>The ApplicationModel.IResourceBuilder`1.
This method is not available in polyglot app hosts. Use MongoDBBuilderExtensions.WithInitFiles instead.
WithInitFiles(IResourceBuilder<MongoDBServerResource>, string)Section titled WithInitFiles(IResourceBuilder<MongoDBServerResource>, string)extensionIResourceBuilder<MongoDBServerResource>
Copies init files into a MongoDB container resource.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<MongoDBServerResource> WithInitFiles(
this IResourceBuilder<MongoDBServerResource> builder,
string source)
{
// ...
}
}
builderIResourceBuilder<MongoDBServerResource>The resource builder.
sourcestringThe source file or directory on the host to copy into the container.
IResourceBuilder<MongoDBServerResource>The ApplicationModel.IResourceBuilder`1.
WithMongoExpress(IResourceBuilder<T>, Action<IResourceBuilder<MongoExpressContainerResource>>, string?)Section titled WithMongoExpress(IResourceBuilder<T>, Action<IResourceBuilder<MongoExpressContainerResource>>, string?)extensionIResourceBuilder<T>
Adds a MongoExpress administration and development platform for MongoDB to the application model.
public static class MongoDBBuilderExtensions
{
public static IResourceBuilder<T> WithMongoExpress<T>(
this IResourceBuilder<T> builder,
Action<IResourceBuilder<MongoExpressContainerResource>>? configureContainer = null,
string? containerName = null)
{
// ...
}
}
builderIResourceBuilder<T>The MongoDB server resource builder.
configureContainerAction<IResourceBuilder<MongoExpressContainerResource>>optionalConfiguration callback for Mongo Express container resource.
containerNamestring?optionalThe name of the container (Optional).
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the container image.