# AddMongoDBReplicaSet

- Module: [Aspire.Hosting.MongoDB](/reference/api/go/aspire.hosting.mongodb.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: `DistributedApplicationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Adds a MongoDB replica set resource to the application model.

## Remarks

This is a "logical" resource that groups multiple `MongoDBServerResource` instances that are annotated as members of the replica set.
The replica set is initialized by the AppHost itself, which is something that only happens when running locally.
Publishing and deploying an application that contains a MongoDB replica set is therefore not supported yet and
this method throws when the AppHost runs in publish mode.
```
var mongo1 = builder.AddMongoDB("mongo-1");
var mongo2 = builder.AddMongoDB("mongo-2");
var replicaSet = builder.AddMongoDBReplicaSet("rs0")
.WithMember(mongo1)
.WithMember(mongo2);
```

## Definition

```go
func (DistributedApplicationBuilder) AddMongoDBReplicaSet(
    name string,
    options ...*AddMongoDBReplicaSetOptions,
) MongoDBReplicaSetResource
```

## Parameters

- `name` (`string`) -- The name of the replica set resource.
- `options` (`...*AddMongoDBReplicaSetOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddMongoDBReplicaSetOptions` argument.

- `UserName` (`*ParameterResource`) -- An optional parameter resource that contains the username for authenticating to the MongoDB replica set. If not provided, a default username will be used.
- `Password` (`*ParameterResource`) -- An optional parameter resource that contains the password for authenticating to the MongoDB replica set. If not provided, a default password will be used.

## Returns

[`MongoDBReplicaSetResource`](/reference/api/go/aspire.hosting.mongodb/mongodbreplicasetresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- `DistributedApplicationBuilder`
